android - ExpandableListView OnChildClickListener with checkbox row not fire when scrolling -
i have baseexpandablelistadapter this:
public view getchildview(final int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { final contentviewholder contentviewholder; view view = convertview; final book book = getchild(groupposition, childposition); if (view == null) { layoutinflater inflater = context.getlayoutinflater(); view = inflater.inflate(r.layout.item_book_row, null); contentviewholder = new contentviewholder(); contentviewholder.tvname = (textview) view.findviewbyid(r.id.tvname); contentviewholder.chkselected = (checkbox) view.findviewbyid(r.id.chkselected); view.settag(contentviewholder); }else{ contentviewholder = (contentviewholder) view.gettag(); } contentviewholder.tvname.settext(book.gettitle()); contentviewholder.chkselected.setchecked(checkstates[groupposition][childposition]); contentviewholder.chkselected.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { book.setselected(contentviewholder.chkselected.ischecked()); checkstates[groupposition][childposition] = contentviewholder.chkselected.ischecked(); ln.d("check on header %d row %d", groupposition, childposition); } }); return view; } public boolean ischildselectable(int groupposition, int childposition) { ln.d("child selected "+groupposition+" : "+childposition); return true; }
with child layout:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:descendantfocusability="blocksdescendants"> <!-- row data --> <textview android:id="@+id/tvname" android:layout_width="wrap_content" android:layout_height="wrap_content" > </textview> <checkbox android:id="@+id/chkselected" android:focusable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_marginleft="@dimen/item_vertical_margin" android:layout_marginright="@dimen/item_vertical_margin" /> </relativelayout>
and here fragment view:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <expandablelistview android:id="@+id/lstcatbook" android:layout_width="match_parent" android:layout_height="fill_parent" android:groupindicator="@null"> </expandablelistview> </linearlayout>
then register setonchildclicklistener
on fragment.
lstcatbook.setonchildclicklistener(new onchildclicklistener() { @override public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) { log.d("click on group " +groupposition +" child " + childposition); return false; } });
everything fine when click on row item or checkbox. problem when scroll listview bottom, can't click on row item again (the onchildclick
not fired ) while check box can work
have no ideas issue. have searched , tried many ways like: set check box focusable = false
, descendantfocusability=blocksdescendants
nothing can help.
wrong? appreciated.
finally figure out problem: cause use set expand group if listview. don't know why setonchildclicklistener
doesn't work in case. can work around catch click event on convert view getchildview , notify main view.
something that:
public view getchildview(final int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { //load data convertview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // notify main view using listener } }); return converview; }