android - How to add a custom element to the recyclerview? -


i have recyclerview data. tried add custom first element.

 if(position == 0) {         trend item = items.get(holder.getadapterposition());         int = 0;         items.add(i, item);  }   @override public int getitemviewtype(int position) {     if (position == 0) return 1;     else return 2; }   @override public myviewholder oncreateviewholder(viewgroup parent, int viewtype) {    if (viewtype == 1) {         inflater = layoutinflater.from(parent.getcontext());         return new myviewholder(layoutinflater.from(parent.getcontext()).inflate(r.layout.item_trendsnewuser, parent, false));     } else {         inflater = layoutinflater.from(parent.getcontext());         return new myviewholder(layoutinflater.from(parent.getcontext()).inflate(r.layout.item_trends, parent, false));     } 

i duplicating first element twice. how add custom row custom options?

you should create 2 viewholder different views , in itemviewtype check specific position , according inflate specific viewholder.

here code this.

  public int getitemviewtype(int position) {         if (products.size()==0){             return 0;         }else if (products.get(position)== 0){             return 0;         }else             return 1;         }         return super.getitemviewtype(position);     } 

and viewholder:

public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) {     if (viewtype== 0){         view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.firsttimeview,parent,false);         return new movieviewholder(view);     }else if (viewtype==1)     {         view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.otherviews,parent,false);         return new otherviewholder(view);     }else{         return null;     } } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -