I have researched lot before posting this question am using cursorrecyclerviewadapter in that how can i use multiple view type i could not find any sample on this now let me explain my problem i need to add header to my recyclerview items like alphabetical header how can i achieve this with cursor recyclerview adapter here let me post my code:
public class CustomerListAdapter extends CursorRecycleViewAdapter<CustomerListAdapter.MyViewHolder> implements View.OnClickListener , RecyclerViewFastScroller.BubbleTextGetter{
int position;
Cursor cursor;
ColorGenerator generator = ColorGenerator.MATERIAL;
private OnItemClickListener onItemClickListener;
List<CustomerModel>list;
public CustomerListAdapter(Context mContext, Cursor cursor) {
super(mContext, cursor);
}
public void setOnItemClickListener(final OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
@Override
public String getTextToShowInBubble(int pos) {
return Character.toString(cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_Name)).charAt(0));
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
TextView textname;
TextView status;
TextView textphnum;
TextView textdegree;
TextView textemail;
ImageView call;
public MyViewHolder(final View itemView) {
super(itemView);
this.textname = (TextView) itemView.findViewById(R.id.subject);
this.status = (TextView) itemView.findViewById(R.id.customerstatus);
this.textemail = (TextView) itemView.findViewById(R.id.username);
this.textdegree=(TextView)itemView.findViewById(R.id.status);
this.call = (ImageView) itemView.findViewById(R.id.imageView);
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.customeradapterview, parent, false);
MyViewHolder myViewHolder = new MyViewHolder(view);
view.setOnClickListener(this);
return myViewHolder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, Cursor cursor) {
TextView textViewName = holder.textname;
TextView textstatus = holder.status;
TextView textphnumbr = holder.textphnum;
TextView textemail=holder.textemail;
String companygrp = cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_Name));
String email=cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_EmailID));
if(email.length()>=20){
String s= email.substring(0,20)+"...";
textemail.setText(s);
}
else {
textemail.setText(email);
}
//textemail.setText(cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_EmailID)));
String status=cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_Status));
if(status.equals("Active")){
textstatus.setTextColor(Color.parseColor("#006400"));
}
else {
textstatus.setTextColor(Color.parseColor("#8B0000"));
}
textstatus.setText(status);
textphnumbr.setText(cursor.getString(cursor.getColumnIndex(CustomerModel.Customer_MobileNumber)));
String s1 = companygrp.substring(0, 1).toUpperCase() + companygrp.substring(1).toLowerCase();
textViewName.setText(s1);
ColorGenerator generator = ColorGenerator.DEFAULT;
String com= s1.substring(0,1);
TextDrawable drawable = TextDrawable.builder()
.buildRound((com).toUpperCase(), generator.getRandomColor());
holder.call.setImageDrawable(drawable);
/* for (int i = 0; i < companygrp.length(); i++) {
String s1 = companygrp.substring(0, 1).toUpperCase() + companygrp.substring(1).toLowerCase();
textViewName.setText(s1);
ColorGenerator generator = ColorGenerator.DEFAULT;
String com= s1.substring(0,1);
TextDrawable drawable = TextDrawable.builder()
.buildRound((com).toUpperCase(), generator.getRandomColor());
holder.call.setImageDrawable(drawable);
}*/
}
@Override
public void onClick(View v) {
final RecyclerView recyclerView = (RecyclerView) v.getParent();
position = recyclerView.getChildLayoutPosition(v);
if (position != RecyclerView.NO_POSITION) {
final Cursor cursor = this.getItem(position);
this.onItemClickListener.onItemClicked(cursor);
}
}
public interface OnItemClickListener {
void onItemClicked(Cursor cursor);
}
}
How to add header to my recyclerview am struck in this can anyone tell me the solution for this Thanks in advance!!