android - ImageView not clickable inside ListView -
i'm trying set onclicklistener
imageview
inside listview
item. adapter: contactlistadapter.java
public class contactlistadapter extends arrayadapter<contactiteminterface> { private int resource; // store resource layout id 1 row private boolean insearchmode = false; private contactssectionindexer indexer = null; public contactlistadapter(context _context, int _resource, list<contactiteminterface> _items) { super(_context, _resource, _items); resource = _resource; // need sort items array first, pass indexer collections.sort(_items, new contactitemcomparator()); setindexer(new contactssectionindexer(_items)); } // data population row here // subclass overwrite draw more items public void populatedataforrow(view parentview, contactiteminterface item, int position) { // default draw item } // should override subclass if necessary @override public view getview(int position, view convertview, viewgroup parent) { viewgroup parentview; contactiteminterface item = null; if (getcount() > position) { item = getitem(position); } // log.i("contactlistadapter", "item: " + item.getitemforindex()); parentview = (viewgroup) layoutinflater.from(getcontext()).inflate(resource, parent, false); // first section item, draw section on top // showsectionviewiffirstitem(parentview, item, position); // set row items here if (getcount() > position) { populatedataforrow(parentview, item, position); } return parentview; } public boolean isinsearchmode() { return insearchmode; } public void setinsearchmode(boolean insearchmode) { this.insearchmode = insearchmode; } public contactssectionindexer getindexer() { return indexer; } public void setindexer(contactssectionindexer indexer) { this.indexer = indexer; } }
adaptercontactlist.java
public class adaptercontactlist extends contactlistadapter { private onclicklistener listener; private onclicklistener oninfoclicklistener; private onclicklistener onitemclicklistener; private arraylist<user> select = null; public adaptercontactlist(context _context, int _resource, list<contactiteminterface> _items) { super(_context, _resource, _items); } public void setselectarray(arraylist<user> select) { this.select = select; this.notifydatasetchanged(); } public void setonclicklistener(onclicklistener listener) { this.listener = listener; } public void setoninfoclicklistener(onclicklistener l){ this.oninfoclicklistener = l; } public void setonitemclicklistenercustom(onclicklistener l){ this.oninfoclicklistener = l; } // override custom drawing public void populatedataforrow(view parentview, contactiteminterface item, int position) { // default draw item view infoview = parentview.findviewbyid(r.id.inforowcontainer); infoview.settag(position); textview fullnameview = (textview) infoview.findviewbyid(r.id.tv_name); view tv_grey = infoview.findviewbyid(r.id.tv_grey); view tv_green = infoview.findviewbyid(r.id.tv_green); view tv_red = infoview.findviewbyid(r.id.tv_red); view tv_yellow = infoview.findviewbyid(r.id.tv_yellow); imageview iv_user = (imageview) infoview.findviewbyid(r.id.im_calls); view pending_cont = infoview.findviewbyid(r.id.pending_cont); imageview btninfo = (imageview)infoview.findviewbyid(r.id.btn_info); if(btninfo != null){ btninfo.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { toast.maketext(getcontext(), "button", toast.length_short).show(); } }); } if (tv_green != null) { if(tv_grey != null){ tv_grey.setvisibility(view.gone); } tv_green.setvisibility(view.gone); tv_red.setvisibility(view.gone); tv_yellow.setvisibility(view.gone); } if (build.version.sdk_int >= build.version_codes.lollipop) { view line_end = infoview.findviewbyid(r.id.line_end); line_end.setvisibility(view.visible); } if (item instanceof contactlistitem) { contactlistitem contactitem = (contactlistitem) item; fullnameview.settext(contactitem.getfullname()); if (contactitem.getavatar() != null) { myproject.loadimage(contactitem.getavatar(), iv_user); } else { user us1 = myproject.gettempuser(contactitem.getmyprojectid()); if (us1 != null) { myproject.loadimage(us1.getavatar(), iv_user); } } if (tv_green != null) { int status = myproject.getuserstatus(contactitem.getmyprojectid()); myproject.debug("" + status); if (status != myproject.status_none) { if (status == myproject.status_online) { tv_green.setvisibility(view.visible); } if (status == myproject.status_away) { tv_yellow.setvisibility(view.visible); } if (status == myproject.status_dnd) { tv_red.setvisibility(view.visible); } }else{ if(tv_grey != null) { tv_grey.setvisibility(view.visible); } } } if (infoview.findviewbyid(r.id.checkbox) != null) { checkbox checkbox = (checkbox) infoview .findviewbyid(r.id.checkbox); if (select != null) { checkbox.setchecked(select.indexof(contactitem.getuser()) >= 0); } else { checkbox.setchecked(false); } } if (listener != null) { view button_add = infoview.findviewbyid(r.id.add_cont); if (contactitem.getuser().ispending()) { pending_cont.setvisibility(view.visible); button_add.setvisibility(view.gone); infoview.setonclicklistener(listener); } else { pending_cont.setvisibility(view.gone); button_add.setvisibility(view.visible); button_add.setonclicklistener(listener); infoview.setonclicklistener(listener); } } infoview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { toast.maketext(v.getcontext(), "avatar", toast.length_short).show(); } }); } } @override public boolean isenabled(int position) { return true; } }
please @ btninfo
. setted him onclicklistener
, in debug mode convinced setted, doesn't work. ignored.
here layout file:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/inforowcontainer" android:layout_width="match_parent" android:layout_height="44dp" android:background="@drawable/dialog_buttons_background" android:descendantfocusability="blocksdescendants"> <com.myproject.custom.cfroundimageview android:id="@+id/im_calls" android:layout_width="32dp" android:layout_height="32dp" android:layout_marginleft="6dp" android:layout_margintop="6dp" android:contentdescription="@string/temp" android:scaletype="fitxy" android:src="@drawable/fb_placeholder"/> <com.myproject.custom.cftextview android:id="@+id/tv_grey" android:layout_width="@dimen/status_side_size" android:layout_height="@dimen/status_side_size" android:layout_alignbottom="@+id/im_calls" android:layout_alignright="@+id/im_calls" android:background="@drawable/ic_not_in_contact"/> <com.myproject.custom.cftextview android:id="@+id/tv_green" android:layout_width="@dimen/status_side_size" android:layout_height="@dimen/status_side_size" android:layout_alignbottom="@+id/im_calls" android:layout_alignright="@+id/im_calls" android:background="@drawable/ic_status_online"/> <com.myproject.custom.cftextview android:id="@+id/tv_yellow" android:layout_width="@dimen/status_side_size" android:layout_height="@dimen/status_side_size" android:layout_alignbottom="@+id/im_calls" android:layout_alignright="@+id/im_calls" android:background="@drawable/ic_status_not_presents"/> <com.myproject.custom.cftextview android:id="@+id/tv_red" android:layout_width="@dimen/status_side_size" android:layout_height="@dimen/status_side_size" android:layout_alignbottom="@+id/im_calls" android:layout_alignright="@+id/im_calls" android:background="@drawable/ic_status_offline"/> <com.myproject.custom.cftextview android:id="@+id/tv_name" android:layout_width="match_parent" android:layout_height="44dp" android:layout_centervertical="true" android:layout_marginleft="44dp" android:layout_marginright="30dp" android:ellipsize="end" android:gravity="left|center_vertical" android:maxlines="1" android:text="@string/text_contacts" android:textcolor="@color/color_grey5" android:textsize="16sp" app:typeface="opensans-light"/> <textview android:id="@+id/line_end" android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginright="36dp" android:layout_margintop="43dp" android:background="@color/color_gray2" android:visibility="gone"/> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btn_info" android:src="@drawable/ic_info" android:layout_alignparentright="true" android:layout_alignparentend="true" android:clickable="true" android:padding="8dp" android:layout_centervertical="true" android:layout_marginright="30dp" /> </relativelayout>
imageview
never clicks! tried set clcikable=true
imageview
i tried set 'focusable=false focusableintouchmode=false' child of item.
i tried use descendantfocusability="blocksdescendants"
on item root view.
i tried combine method 1 another.
and imageview
still not clickable.
try (things in *** .... ****) ...... public void populatedataforrow(view parentview, contactiteminterface item, int position) { // default draw item view infoview = parentview.findviewbyid(r.id.inforowcontainer); infoview.settag(position); textview fullnameview = (textview) infoview.findviewbyid(r.id.tv_name); view tv_grey = infoview.findviewbyid(r.id.tv_grey); view tv_green = infoview.findviewbyid(r.id.tv_green); view tv_red = infoview.findviewbyid(r.id.tv_red); view tv_yellow = infoview.findviewbyid(r.id.tv_yellow); imageview iv_user = (imageview) infoview.findviewbyid(r.id.im_calls); view pending_cont = infoview.findviewbyid(r.id.pending_cont); imageview btninfo = (imageview)infoview.findviewbyid(r.id.btn_info); ****btninfo.setfocusable(false);**** if(btninfo != null){ btninfo.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { toast.maketext(getcontext(), "button", toast.length_short).show(); } }); } ....... // code
Comments
Post a Comment