android - On Item click of listview not responding -
i have custom adapter set listview itemclickevent not working . have included adapter inside main activity.i have tried many suggestions havent got solutions till yet.
public class mainactivity extends activity { private listview listview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); model.loadmodel(); listview = (listview) findviewbyid(r.id.list); string[] ids = new string[model.items.size()]; (int i= 0; < ids.length; i++){ ids[i] = integer.tostring(i+1); } graphlistadapter adapter = new graphlistadapter (this,r.layout.list_row, ids); listview.setadapter(adapter); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } public class graphlistadapter extends baseadapter { private final context context; private final string[] ids; private final int rowresourceid; public graphlistadapter(context context, int textviewresourceid, string[] objects) { super(); this.context = context; this.ids = objects; this.rowresourceid = textviewresourceid; } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view rowview = inflater.inflate(rowresourceid, parent, false); imageview imageview = (imageview) rowview.findviewbyid(r.id.imageview); textview textview = (textview) rowview.findviewbyid(r.id.dashboard_name); textview textview2 = (textview) rowview.findviewbyid(r.id.dashboard_info); int id = integer.parseint(ids[position]); string imagefile = model.getbyid(id).imagename; textview.settext(model.getbyid(id).dashboardname); textview2.settext(model.getbyid(id).information); // input stream inputstream ims = null; try { ims = context.getassets().open(imagefile); } catch (ioexception e) { e.printstacktrace(); } // load image drawable drawable d = drawable.createfromstream(ims, null); // set image imageview imageview.setimagedrawable(d); return rowview; } private onitemclicklistener clicklistener = new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int pos, long arg3) { // todo auto-generated method stub system.out.println(pos); } }; @override public int getcount() { // todo auto-generated method stub return 2; } @override public object getitem(int position) { // todo auto-generated method stub return null; } @override public long getitemid(int position) { // todo auto-generated method stub return 0; } } }
my list row contains image , text both...................
use listview.setonitemclicklistener
inside oncreate()
:
graphlistadapter adapter = new graphlistadapter (this,r.layout.list_row, ids); listview.setadapter(adapter); listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { // todo auto-generated method stub } });
Comments
Post a Comment