java - Working with several RecyclerViews -


in android app, i've been using several recyclerviews different , requirements. number increased, thought of unifying them. question recyclerviews different requirements, should use different adapters (layout files can't same) or 1 universal adapter this:

public class dataadapter extends recyclerview.adapter < dataadapter.viewholder > {  variables...  public dataadapter(context context) {   }   @override  public dataadapter.viewholder oncreateviewholder(viewgroup viewgroup, int i) {   //   if(the_condition_to check_which_recycler_view)   //   inflate a;   //   else if(other_condition)   //   inflate b;   //   else ...   return xyz;  }  @override  public void onbindviewholder(final viewholder viewholder, int i) {   // if(the_condition_to check_which_recycler_view)   //       this;   //       else if(other_condition)   //       this;   //       else ...  }  @override  public int getitemcount() {   return xyz;  }   public class viewholder extends recyclerview.viewholder {   //all views declared here   public viewholder(view view) {    super(view);    //allviewsdefinedhere   }  } } 

another little thing ask have seen various libraries fastadapter says simplify whole adapter work couldn't understand how help. there issue manual adapter approach?

you can follow model-view-presenter approach requirement. having baseviewholder , baseadapter , different secondaryviewholders extending baseviewholders each viewtype.

since layout files cannot same, secondaryviewholders independent , contain respective layout files.

you can read this more details

you can find full code here


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -