android - Add section to recycle View in run time with dynamic array -
i trying add section/header in recycle view
have handle section stuff in
@override public int getitemviewtype(int position) { // here custom logic choose view type return position == 0 ? section: item;
}
but having arraylist have n number of data . 1st section may have 10 row 2nd may have 2 row .so how define section in case .where come know end of 1st section ? , put 2nd one
iterate on each model , remember previous section name of each model item. when ever find new section name, map index.
in adapter return items count fewer data set.
@override public int getitemcount(){ return mdata.size() + msections.size(); }
always use position + 1
, because 1 position ahead.
whenever reach position belongs mapped indexes, return section type , bind accordingly:
@override public int getitemviewtype(int position) { // here custom logic choose view type return ispositionsectionindex(position) ? view_type_section: view_type_item; }
Comments
Post a Comment