android listview - setOnCheckedChangeListener -
i want expand group item when check on it, reasons can't collapse group item after expands.
can please tell me doing wrong?
public view getgroupview(final int groupposition, boolean isexpanded, view convertview, viewgroup parent) { final groupholder holder; final viewgroup viewgroup = parent; if (convertview == null) { convertview = layoutinflater.inflate(r.layout.group_list, null); holder = new groupholder(); holder.checkbox = (checkbox) convertview.findviewbyid(r.id.cb); holder.imageview = (imageview) convertview.findviewbyid(r.id.label_indicator); holder.title = (textview) convertview.findviewbyid(r.id.group_title); convertview.settag(holder); } else { holder = (groupholder) convertview.gettag(); } holder.imageview.setimageresource(groupstatus[groupposition] == 0 ? r.drawable.group_down: r.drawable.group_up); final item groupitem = getgroup(groupposition); holder.title.settext(groupitem.name); holder.checkbox.setoncheckedchangelistener(new oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (!all_checked) { arraylist<item> childitem = getchild(groupitem); (item children : childitem) children.ischecked = ischecked; } groupitem.ischecked = ischecked; // todo auto-generated method stub if(groupitem.ischecked) ((expandablelistview) viewgroup).expandgroup(groupposition); notifydatasetchanged(); new handler().postdelayed(new runnable() { public void run() { // todo auto-generated method stub if (all_checked) all_checked = false; } }, 10); } }); holder.checkbox.setchecked(groupitem.ischecked); return convertview; }
//below logcat when put check mark on group0:
08-19 07:49:08.860: d/group pos: 0 08-19 07:49:08.863: d/group pos: 0 08-19 07:49:08.887: d/group pos: 4
i noticed showed groupid0 & 4 when clicked on group0
edit: re-wrote make clear others understand better
i have 1 idea. first remove checkbox , try collapse
lv.setongroupexpandlistener(new ongroupexpandlistener() { @override public void ongroupexpand(int groupposition) { if (lastexpandedposition != -1 && groupposition != lastexpandedposition) { lv.collapsegroup(lastexpandedposition); } lastexpandedposition = groupposition; }
});
if still getting problem please ping me if not getting problem add view , view group
Comments
Post a Comment