android - OnListItemClick event not working -



android - OnListItemClick event not working -

this question exact duplicate of:

onlistitemclick event not working

i have been facing problem...there 5 different java classes mainactivity, application, applicationadapter, fetchdata ,fetchdatalistener.. binding mysql info api in listview... trying fire click event on listview getting error....here code...

mainactivity.java

@override public void onfetchcomplete(list<applicity> data) { // dismiss progress dialog if(dialog != null) dialog.dismiss(); // create new adapter applicationadapter adapter = new applicationadapter(this, data); // set adapter list setlistadapter(adapter); } public void onlistitemclick(listview l, view v, int position, long id) { applicity app= new applicity(); int p =app.getposition(position); toast.maketext(this,p,toast.length_long).show(); }

applicationadapter.java

public class applicationadapter extends arrayadapter<applicity>{ private list<applicity> items; public applicationadapter(context context, list<applicity> items) { super(context, r.layout.app_custom_list, items); this.items = items; } @override public int getcount() { homecoming items.size(); } @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if(v == null) { layoutinflater li = layoutinflater.from(getcontext()); v = li.inflate(r.layout.app_custom_list, null); } applicity app = items.get(position); if(app != null) { imageview icon = (imageview)v.findviewbyid(r.id.appicon); textview titletext = (textview)v.findviewbyid(r.id.titletxt); linearlayout ratingcntr = (linearlayout)v.findviewbyid(r.id.ratingcntr); textview dltext = (textview)v.findviewbyid(r.id.dltxt); if(icon != null) { resources res = getcontext().getresources(); string sicon = "com.sj.jsondemo:drawable/" + app.geticon(); icon.setimagedrawable(res.getdrawable(res.getidentifier(sicon, null, null))); } if(titletext != null) titletext.settext(app.gettitle()); if(dltext != null) { numberformat nf = numberformat.getnumberinstance(); dltext.settext(nf.format(app.gettotaldl())+" dl"); } if(ratingcntr != null && ratingcntr.getchildcount() == 0) { /* * max rating: 5 */ for(int i=1; i<=5; i++) { imageview iv = new imageview(getcontext()); if(i <= app.getrating()) { iv.setimagedrawable(getcontext().getresources().getdrawable(r.drawable.start_checked)); } else { iv.setimagedrawable(getcontext().getresources().getdrawable(r.drawable.start_unchecked)); } ratingcntr.addview(iv); } } } homecoming v; }

}

applicity.java

public class applicity { private string title; private long totaldl; private int rating; public int position; private string icon; public string gettitle() { homecoming title; } public void settitle(string title) { this.title = title; } public long gettotaldl() { homecoming totaldl; } public void settotaldl(long totaldl) { this.totaldl = totaldl; } public int getrating() { homecoming rating; } public void setrating(int rating) { this.rating = rating; } public string geticon() { homecoming icon; } public void seticon(string icon) { this.icon = icon; } public int getposition(int arg){ homecoming position; }

}

use onitemclicklistener. you're creating new custom method instead of onitemclicklistener.

lv.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { //do here. } });

android listactivity

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -