Closed mhemdan closed 9 years ago
Hey man .. how do you did this? Can you help me please?
Here is my adapter code which is wrapped with the sticky Decor hope it helps
`import android.content.Context; import android.content.Intent; import android.net.Uri; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView;
import java.util.ArrayList;
import ca.barrenechea.widget.recyclerview.decoration.StickyHeaderAdapter;
/**
Created by mohammed on 9/12/15.
*/
public class StickyNumbersHeader extends RecyclerView.Adapter
private Context context;
private LayoutInflater mInflater;
private ArrayList
public void insertItems(ArrayList
return new ViewHolder(view);
}
@Override public void onBindViewHolder(ViewHolder holder, final int position) { holder.number.setText(items.get(position).getNumber()); holder.title.setText(items.get(position).getTitle()); holder.itemContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openDial(items.get(position).getNumber()); } }); }
@Override public int getItemCount() { return items.size(); }
@Override public long getHeaderId(int position) { if(position<=2){ return mHeaderPositions[0]; }else if(position<=7){ return mHeaderPositions[1]; }else if(position<=11){ return mHeaderPositions[2]; }else if(position<=30){ return mHeaderPositions[3]; }else if(position==31){ return mHeaderPositions[4]; }else if(position<=52){ return mHeaderPositions[5]; }else if(position==53){ return mHeaderPositions[6]; }else if(position==54){ return mHeaderPositions[7]; }else if(position<=68){ return mHeaderPositions[8]; }else if(position<=70){ return mHeaderPositions[9]; }else if(position<=81){ return mHeaderPositions[10]; }else{ return mHeaderPositions[11]; } }
@Override public HeaderHolder onCreateHeaderViewHolder(ViewGroup parent) { final View view = mInflater.inflate(R.layout.header_phone, parent, false); return new HeaderHolder(view); }
@Override public void onBindHeaderViewHolder(HeaderHolder viewholder, int position) { viewholder.header.setText(items.get(position).getCategory()); }
static class HeaderHolder extends RecyclerView.ViewHolder { public TextView header;
public HeaderHolder(View itemView) {
super(itemView);
header = (TextView) itemView;
}
}
static class ViewHolder extends RecyclerView.ViewHolder { public TextView title,number; public LinearLayout itemContainer; public ViewHolder(View itemView) { super(itemView);
title = (TextView) itemView.findViewById(R.id.phone_number_tile);
number = (TextView) itemView.findViewById(R.id.phone_number);
itemContainer = (LinearLayout) itemView.findViewById(R.id.item_container);
}
} public void openDial(String phoneNumber){ Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + phoneNumber)); this.context.startActivity(intent); }
}`
how to set different positions for headers like set one header at position 10 and the second one on 13 and so on ? thanks