Android, Button in Listview, not associated with correct row -


i have listview containing textview click on.

i have managed make this, no matter row's textview click on it's clicked on bottom row's.

for example, when click on textview in row 2, acts if clicked on textview in bottom row of screen.

it doesn't seem matter row's textview click on, it's if click on last loaded position's textview.

from reading other related questions, googling, , running debugger, suspect has fact row on bottom of screen last position loaded , when click on uses positions clicklisteners. i've seen need make use of tags resolve this, couldn't quite understand how apply tags , how use tag's position in code.

here custom arrayadapter's getview method , listeners:

    @override public view getview (int position, view convertview, viewgroup parent) {     question = (question) getitem(position);      // or create cached eventview     if(convertview == null){         convertview = (linearlayout) inflater.inflate(mresourceid, null);         questionview = new questionlistitemholder(convertview);         convertview.settag(questionview);     }     else {         questionview = (questionlistitemholder) convertview.gettag();     }      // fill data in each row     filldata();      // setup click listeners row's clickable items     setlisteners();      return convertview; } 

and listener:

    private void setlisteners(){     questionview.getaskedbytextview().setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             intent intent = new intent (context, profileactivity.class);             // seems "question" based off position in getview             // need way have "question" 1             // position of row clicked on, not last row...             parseuser u = question.getuser();              intent.putextra("user", u.getobjectid());             context.startactivity(intent);         }     });      questionview.getfollowbutton().setonclicklistener(new view.onclicklistener(){         @override         public void onclick(view v) {             wantansweractivity();         }     }); } 

how can make button or textview click on associated correct row position?

you need call listeners in getview correct content.if declare in outside of getview.you can't able exact onclick listeners particular position.

@override public view getview (int position, view convertview, viewgroup parent) { question = (question) getitem(position);  // or create cached eventview if(convertview == null){     convertview = (linearlayout) inflater.inflate(mresourceid, null);     questionview = new questionlistitemholder(convertview);     convertview.settag(questionview); } else {     questionview = (questionlistitemholder) convertview.gettag(); }  // fill data in each row filldata(); questionview.getaskedbytextview().setonclicklistener(new                                        view.onclicklistener() {     @override     public void onclick(view v) {         intent intent = new intent (context, profileactivity.class);         // seems "question" based off position in getview         // need way have "question" 1         // position of row clicked on, not last row...         parseuser u = question.getuser();          intent.putextra("user", u.getobjectid());         context.startactivity(intent);     } });  questionview.getfollowbutton().setonclicklistener(new  view.onclicklistener(){     @override     public void onclick(view v) {         wantansweractivity();     } }); }  // setup click listeners row's clickable items   return convertview; 

}


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -