i have view:
list.xml
<linearlayout> <imageview /> <textview /> <textview /> </linearlayout>
inflated view:
main.xml
<horizontalscrollview> <linearlayout/> </horiztontalscrollview>
the data json , dynamic.
try{ products = jsonobj.getjsonarray(constants.product_arr); if(products.length() != 0){ for(int = 0; < products.length(); i++){ jsonobject c = products.getjsonobject(i); string sname = c.getstring(constants.shop_name); string productid = c.getstring(constants.shop_id); string desc = c.getstring(constants.shop_desc); string imageurl = c.get(constants.shop_image_url) == jsonobject.null ? null : c.getstring(constants.product_image_url); string imgwidth = c.get(constants.image_width) == jsonobject.null ? null : c.getstring(constants.image_width); string imgheight = c.get(constants.image_height) == jsonobject.null ? null : c.getstring(constants.image_height); string productownerid = c.getstring(constants.shop_owner_id); if(imgheight != null && imgwidth != null && imageurl != null){ product = new productrowitem(imageurl, sname, productid, desc, integer.parseint(imgheight), integer.parseint(imgwidth), productownerid); productitems.add(product); } } }else{ toast toast = toast.maketext(getapplicationcontext(),"shop null", toast.length_long); toast.setgravity(gravity.center, 0, 0); toast.show(); } }catch(jsonexception e){ throw new runtimeexception(e); }
i inflate list.xml
main.xml
.
final productbaseadapter adapter = new productbaseadapter(context, productitems); linearlayout layout = (linearlayout) findviewbyid(r.id.linear_temp); for(int = 0 ; < adapter.getcount() ; i++){ view item = adapter.getview(i, null, null); layout.addview(item); item.settag("test"+i); }
but, how can have onclicklistener each item? because clicking each item start new activity contains detailed information of each product
. problem on how identify item clicked , how listen onclick. i've know settag()
, gettag()
confuse on how implement these. plan use product id parameter settag
i'll have tag identify product clicked. i'm still trying figure out. time being, can shed light on this, how/ put method onclicklistener , how determine product clicked?
any appreciated.
you can this:-
for(int = 0 ; < adapter.getcount() ; i++){ view item = adapter.getview(i, null, null); item.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { //call details activity here. } }); layout.addview(item); item.settag("test"+i); }
Comments
Post a Comment