java - Universal Image Loader: Get ImageView Object From Tap -
after combing through example project uil have found snag.
this code shows onitemclicklistener. need return imageview object, not null.
@override public object getitem(int position) { return null; }
they don't return item position. can't not override method stuck on how return item. watched google i/o talk listadapters (https://www.youtube.com/watch?v=wdbm6wveo70) , said not cache list of images , return position based off (because erratic behaviour when garbage collector stuff).
so can advise how imageview object uil imageadapater(baseadapter) object?
it's not matter of uil. adapter
handles list of data not view. so, getitem
gives data , array index (position
in code), not imageview
clicked.
to pass view
object adapter, need pass imageview
object listener @ viewholder onclick
event.
first, define interface.
public interface viewclicklistener { void onclickview(view view); }
at view layout inflated, add below code.
private viewclicklistener viewclicklistener; public void setviewclicklistener(viewclicklistener listener) { this.viewclicklistener = listener; }
and, in adapter view,
imageview.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { if (viewclicklistener!= null) viewclicklistener.onclickview(view); } });
in class contains adapter,
public class someactivity implements viewclicklistener { @override public void oncreate(bundle savedinstancestate, persistablebundle persistentstate) { super.oncreate(savedinstancestate, persistentstate); youradapter.setviewclicklistener(this); // listens onclick event inside of adapter view. } @override onclickview(view view){ log.d("test", view); // clicked imageview comes here. } }
Comments
Post a Comment