android - Different adapter in items of recyclerview -
i creating list contains, different types of views. like facebook in showing feeds in mobile application. example times scrollview or times list inside list.
to choice. if add fragment in each item of recyclerview. like
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:layout_width="match_parent" android:name="com.profile.editprofilefragment" android:layout_height="wrap_content"/>
and add item in reclycleview , keep different logic inside it.
can 1 suggest me how go through this.
i don't think it's going possible using fragment row. fragment has own lifecycle don't lies within recyclerview can control. can simple view.
just override several methods in recyclerview.adapter
private arraylist<data> items = new arraylist<>(); // data associated // each row @override public int getitemviewtype(int position) { return items.get(position).getrowtype(); // assuming getter type } @override public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) { switch (viewtype) { case data.type_a: view convertview = layoutinflater.from(parent.getcontext()) .inflate(r.layout.row_feed, parent, false); return new viewholdertypea(convertview); case data.type_b: ... default: return null; } } @override public void onbindviewholder(recyclerview.viewholder holder, int position) { data data = items.get(position); if (holder instanceof viewholdertypea) { viewholdertypea holdera= (viewholdertypea) holder; // manipulate views in view holder type ... }else if (holder instanceof viewholdertypeb){ } }
edit: don't need different adapter each item. need item includes logic. if want have 2 row types, 1 status, 1 photo facebook feed item be:
class data { string status, photourl; }
of course members empty depending on row.
Comments
Post a Comment