listview - How do i add grid and list in same layout (RecyclerView or something similar) in android? -
i want add grid , list in same layout (recyclerview or similar) in android. grid can multiple products , list label products. 2 products in grid width. 1 did in recyclerview items image->: only products no title
now want label items below it
i want this, possibly in efficient way image->: multiple items under 1 label
tried adding label , items in same recycleview, label added product item
public class customcategoryadapter extends recyclerview.adapter {
private list<object> itemsdata; private context mcontext; private final int title = 0; private final int productitem = 1; public customcategoryadapter(activity context, list<object> itemsdata) { mcontext = context; this.itemsdata = itemsdata; } @override public int getitemcount() { return itemsdata.size(); } @override public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) { recyclerview.viewholder viewholder; layoutinflater inflater = layoutinflater.from(parent.getcontext()); view v1; switch(viewtype) { case title: v1 = inflater.inflate(r.layout.title_layout, parent, false); viewholder = new titlelayout(v1); return viewholder; case productitem: v1 = inflater.inflate(r.layout.product_list_item, parent, false); viewholder = new productlistingrecyclergridadapter.viewholder(v1); return viewholder; } return null; } @override public void onbindviewholder(recyclerview.viewholder viewholder, final int position) { try { switch(viewholder.getitemviewtype()) { case title: titlelayout titlelayout = (titlelayout) viewholder; titlelayout.settitle((string)itemsdata.get(position)); break; case productitem: productlistingrecyclergridadapter.viewholder productdetail = (productlistingrecyclergridadapter.viewholder) viewholder; productdetail.itemprice.settext(((productitem)itemsdata.get(position)).getproductprice()); productdetail.txtviewtitle.settext(((productitem)itemsdata.get(position)).gettitle()); //productdetail.imgviewicon.setimageurl(((productitem)itemsdata.get(position)).getimageurl(),gorsingleton.getinstance().getimageloader()); break; } } catch (exception e) { e.printstacktrace(); } } @override public int getitemviewtype(int position) { if (itemsdata.get(position) instanceof string) { return title; } else if (itemsdata.get(position) instanceof productitem) { return productitem; } return -1; }
}
Comments
Post a Comment