android - show 10 items in each row of recycler view with grid layout similar to flipkart app -
i working on e-commerce app. want design home page similar flipkart app.i have used recycler view.i able display data want display first 10 elements list in 1 row i.e. 1 10. in 2 row items shouls 11 20.
right showing 1 15 items in rows list size 15.
screenshot attached. code adapter-
public class recyclerviewadapter3 extends recyclerview.adapter<recyclerviewadapter3.recyclerviewholders> { //private list<itemobject> itemlist; private list<string> itemlist2; private context context; private static final int item_view_type_header = 0; private static final int item_view_type_item = 1; private view header; private gridlayoutmanager llayout; public recyclerviewadapter3(context context) { // this.itemlist = itemlist; // this.itemlist2=itemlist2; this.context = context; } @override public recyclerviewholders oncreateviewholder(viewgroup parent, int viewtype) { log.i("pos on create holder",""+viewtype); /* if (viewtype == item_view_type_header) { return new recyclerviewholders(header); }else {*/ view layoutview = layoutinflater.from(parent.getcontext()).inflate(r.layout.recycler_view, null); recyclerviewholders rcv = new recyclerviewholders(layoutview); return rcv; // } } @override public void onbindviewholder(recyclerviewholders holder, int position) { list<itemobject> rowlistitem = getallitemlist(); /* linearlayoutmanager layoutmanager = new linearlayoutmanager(context); layoutmanager.setorientation(linearlayoutmanager.horizontal);*/ //layoutmanager.scrolltoposition(currpos); llayout = new gridlayoutmanager(context, 1, gridlayoutmanager.horizontal, false); // llayout = new gridlayoutmanager(context, 10); int spacinginpixels = context.getresources().getdimensionpixelsize(r.dimen.spacing); // holder.rview.additemdecoration(new spacesitemdecoration(spacinginpixels)); // llayout.setfullspan(true); holder.rview.sethasfixedsize(true); holder.rview.setlayoutmanager(llayout); final recyclerviewadapter rcadapter = new recyclerviewadapter(context, rowlistitem); holder.rview.setadapter(rcadapter); } @override public int getitemcount() { return 5; } public class recyclerviewholders extends recyclerview.viewholder{ public recyclerview rview; public recyclerviewholders(view itemview) { super(itemview); rview = (recyclerview) itemview.findviewbyid(r.id.recycler_view); } } private list<itemobject> getallitemlist(){ list<itemobject> allitems = new arraylist<itemobject>(); allitems.add(new itemobject("united states", r.drawable.ic_launcher)); allitems.add(new itemobject("canada", r.drawable.ic_launcher)); allitems.add(new itemobject("united kingdom", r.drawable.ic_launcher)); allitems.add(new itemobject("germany", r.drawable.ic_launcher)); allitems.add(new itemobject("sweden", r.drawable.ic_launcher)); allitems.add(new itemobject("united kingdom", r.drawable.ic_launcher)); allitems.add(new itemobject("germany", r.drawable.ic_launcher)); allitems.add(new itemobject("sweden", r.drawable.ic_launcher)); allitems.add(new itemobject("united states", r.drawable.ic_launcher)); allitems.add(new itemobject("canada", r.drawable.ic_launcher)); allitems.add(new itemobject("united kingdom", r.drawable.ic_launcher)); return allitems; }
}
Comments
Post a Comment