android - ListViewAdapter changing few buttons -
i created adapter list view. want click on button , change text on it. when click button few buttons changed not this.
this listviewadapter.java
public class listviewadapter extends arrayadapter<post> { private list<post> mpostlist; private context mcontext; public listviewadapter(list<post> postlist, context context){ super(context, r.layout.post, postlist); mpostlist = postlist; mcontext = context; } public view getview(final int position, view convertview, viewgroup parent){ final viewholderitem viewholder; if(convertview==null){ convertview = layoutinflater.from(getcontext()).inflate(r.layout.post, parent, false); viewholder = new viewholderitem(); convertview.settag(viewholder); viewholder.mplusimagebutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { viewholder.mplusimagebutton.settext("a"); } }); }else{ viewholder = (viewholderitem) convertview.gettag(); } return convertview; } static class viewholderitem { public button mplusimagebutton; public int position; } @override public int getcount(){ return mpostlist.size(); }
}
here can create boolean variable inside post class , instantiate false whenever button clicked make true , inside getview method make use of variable. getview method below.
public view getview(final int position, view convertview, viewgroup parent){ final viewholderitem viewholder; if(convertview==null){ convertview = layoutinflater.from(getcontext()).inflate(r.layout.post, parent, false); viewholder = new viewholderitem(); viewholder.mplusimagebutton = convertview.findviewbyid(r.id.someid); viewholder.mplusimagebutton = convertview.findviewbyid(r.id.someid); convertview.settag(viewholder); }else{ viewholder = (viewholderitem) convertview.gettag(); } post post = mpostlist.get(position); viewholder.mplusimagebutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { viewholder.mplusimagebutton.settext("a"); post.isclicked = true; } }); if(post.isclicked) viewholder.mplusimagebutton.settext("a"); else viewholder.mplusimagebutton.settext("b"); return convertview; }
Comments
Post a Comment