java - Android viewholder onclick updates more instances -
for android application i'm using viewholder pattern. whenever click on imageview in listview row updated other rows getting updated.
whenever click "like" button other images receive image liked user. how possible?
here viewholder code:
public class myadapter extends arrayadapter<mymodel> { context context; int layoutresourceid; list<mymodel> data = null; public myadapter(context context, int layoutresourceid, list<mymodel> data) { super(context, layoutresourceid, data); this.layoutresourceid = layoutresourceid; this.context = context; this.data = data; } @override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; final blockholder holder; if (row == null) { layoutinflater inflater = ((activity) context).getlayoutinflater(); row = inflater.inflate(layoutresourceid, parent, false); holder = new blockholder(); holder.imgicon = (imageview) row.findviewbyid(r.id.imgicon); holder.totalvotes = (textview) row.findviewbyid(r.id.totalvotes); holder.likeicon = (imageview) row.findviewbyid(r.id.likeicon); holder.dislikeicon = (imageview) row.findviewbyid(r.id.dislikeicon); holder.saveicon = (imageview) row.findviewbyid(r.id.saveicon); row.settag(holder); } else { holder = (blockholder) row.gettag(); } mymodel myblock = data.get(position); imageloader.getinstance().displayimage(myblock.getimage(), holder.imgicon); final int totallikes = myblock.getlikes() - myblock.getdislikes(); holder.totalvotes.settext(totallikes + " likes"); final imageview = holder.likeicon; holder.likeicon.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // updates other views... holder.likeicon.setbackgroundresource(r.drawable.thumbs_up_mouse); } }); return row; } private static class blockholder{ imageview imgicon; textview totalvotes; imageview dislikeicon; imageview likeicon; imageview saveicon; }
Comments
Post a Comment