Android: Expandable ListView with parent checkbox and child checkbox -


i want create expandable listview parent checkboxes , child checkboxes. whenever parent checkbox selected child checkboxes should selected. whenever child checkboxes selected/unselected parent checkboxes should behave appropriately.

i have tried below adapter code after referring link create expandable listview group , child checkbox.

public class filterlistexpandablelistitemadapter extends baseexpandablelistadapter {  private map<explistgroupitem, list<explistchilditem>> groupchild; private list<explistgroupitem> groups; private activity context; private expandablelistview elv;  public filterlistexpandablelistitemadapter(activity context, list<explistgroupitem> cities,                              map<explistgroupitem, list<explistchilditem>> cityarea, expandablelistview elv) {     this.context = context;     this.groupchild = cityarea;     this.groups = cities;     this.elv = elv; }  @override public int getgroupcount() {     return groups.size(); }  @override public int getchildrencount(int groupposition) {     return groupchild.get(groups.get(groupposition)).size(); }  @override public object getgroup(int groupposition) {     return groups.get(groupposition); }  @override public object getchild(int groupposition, int childposition) {     return groupchild.get(groups.get(groupposition)).get(childposition); }  @override public long getgroupid(int groupposition) {     return groupposition; }  @override public long getchildid(int groupposition, int childposition) {     return childposition; }  @override public boolean hasstableids() {     return true; }  @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) {    explistgroupitem group = (explistgroupitem) getgroup(groupposition);     if (convertview == null) {         layoutinflater infalinflater = (layoutinflater) context                 .getsystemservice(context.layout_inflater_service);         convertview = infalinflater.inflate(r.layout.filter_drawer_list_parent_item,                 null);     }     groupviewholder groupholder = new groupviewholder();     groupholder.parentcheckbox = (checkbox) convertview.findviewbyid(r.id.chkbox_filter_drawer_city);     groupholder.parentcheckbox.settypeface(null, typeface.bold);     groupholder.parentcheckbox.settext(group.getgroupname());     groupholder.parentcheckbox.setselected(group.isselected());     groupcheckchangedlistener groupcheckchangedlistener = new groupcheckchangedlistener();     groupholder.parentcheckbox.setoncheckedchangelistener(groupcheckchangedlistener);     convertview.settag(groupholder);     return convertview; }  @override public view getchildview(final int groupposition, final int childposition,                          boolean islastchild, view convertview, viewgroup parent){     final explistchilditem child = (explistchilditem) getchild(groupposition, childposition);     layoutinflater inflater = context.getlayoutinflater();      if (convertview == null) {         convertview = inflater.inflate(r.layout.filter_drawer_list_child_item, null);     }     childviewholder childholder = new childviewholder();     childholder.childcheckbox =(checkbox) convertview.findviewbyid(r.id.chkbox_filter_drawer_area);     childholder.childcheckbox.setselected(child.isselected());     childholder.childcheckbox.settext(child.getchildname());     convertview.settag(childholder);     return convertview; }  @override public boolean ischildselectable(int i, int i1) {     return true; }  static class childviewholder {    checkbox childcheckbox; }  static class groupviewholder {     checkbox parentcheckbox; }   private class groupcheckchangedlistener implements checkbox.oncheckedchangelistener{      @override     public void oncheckedchanged(compoundbutton compoundbutton, boolean b) {         explistgroupitem group = new explistgroupitem();         checkbox chk = (checkbox) compoundbutton;         group.setgroupname(chk.gettext().tostring());         for(explistchilditem item: groupchild.get(group)){             item.setisselected(true);         }         notifydatasetchanged();      } }} 

the problem here have checked debugger option. underlying data has changed. not reflecting on ui. when check parent, corresponding children not selected.

can please suggest doing wrong here? best way handle scenario required?

in getchildview method should check if parentcheckbox selected , if yes then

childholder.childcheckbox.setselected(true);  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -