java - ImageAdapter onClick goes wrong -
i'm trying set onclick listener on imageview in adapter of gridview. however, weird thing happens: content of onclick function affects other views in gridview.
there reason don't click listener on gridview, need solution via imageadapter.
logcat called once click, reason, other imageviews affected function.
here's relevant code:
public view getview(final int position, view convertview, viewgroup parent) { final viewholder holder; if(convertview == null) { holder = new viewholder(); convertview = minflater.inflate(r.layout.row_multiphoto_item, null); holder.tickimageview = (imageview) convertview.findviewbyid(r.id.tickimageview); holder.imageview = (imageview) convertview.findviewbyid(r.id.imageview1); holder.imageviewlayout = (linearlayout)convertview.findviewbyid(r.id.imageviewlayout); convertview.settag(holder); } else{ holder = (viewholder) convertview.gettag(); } holder.imageview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { imageview imageview = (imageview)v; int id = imageview.getid(); imageview.setvisibility(view.gone);/* if(!thumbnailsselection[id]){ log.d(global.tag, "click"); holder.tickimageview.setvisibility(view.visible); holder.imageviewlayout.setbackgroundresource(r.drawable.imageview_selected); thumbnailsselection[id] = true; } else{ holder.tickimageview.setvisibility(view.gone); holder.imageviewlayout.setbackgroundresource(r.drawable.imageview_unselected); thumbnailsselection[id] = false; } */ }
});
holder.imageview.setid(position); holder.imageviewlayout.setid(position); holder.tickimageview.setid(position); holder.imageview.setimagebitmap(thumbnails[position]); return convertview; } class viewholder { imageview imageview; linearlayout imageviewlayout; imageview tickimageview; int id; }
in baseadapters, view recycled. means if set view invisible, add other view invisible when scroll. avoid that, sure set again visibility of yout view in getview method:
holder.imageview.setvisibility(view.visible) holder.imageview.setonclicklistener(new oncl...
also have store each visibility state, in order reassing visible or invisible.
Comments
Post a Comment