Android ExpanableListView getChildView does not get called -


i working on following code. contains multiple expandable listview. works fine except getchildview of subchild not called. getting groupcount, groupview, , childcount correctly.

import java.util.arraylist; import java.util.hashmap; import java.util.list;  import com.vera.r.color; import com.vera.navdrawer.navdraweritem; import android.content.context; import android.content.res.typedarray; import android.graphics.color; import android.graphics.typeface; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup; import android.widget.baseexpandablelistadapter; import android.widget.expandablelistview; import android.widget.imageview; import android.widget.relativelayout; import android.widget.textview; import android.widget.expandablelistview.onchildclicklistener; import android.widget.expandablelistview.ongroupclicklistener; import android.widget.expandablelistview.ongroupcollapselistener; import android.widget.expandablelistview.ongroupexpandlistener; import android.widget.toast;  public class listadapter_selectdevice extends baseexpandablelistadapter {      private context _context;     public arraylist<navdraweritem> _listdataheader; // header titles     public hashmap<string, arraylist<navdraweritem>> _listdatachild;      public listadapter_selectdevice(context context, arraylist<navdraweritem> listdataheader, hashmap<string, arraylist<navdraweritem>> listdatachild) {         this._context = context;         this._listdataheader = listdataheader;          this._listdatachild = listdatachild;      }      @override     public object getchild(int groupposition, int childposititon) {         navdraweritem l = this._listdatachild.get(this._listdataheader.get(groupposition).gettitle()).get(childposititon);         return l;         /*string s = this._listdatachild.get(this._listdataheader.get(groupposition).gettitle()).get(childposititon);         return s;*/     }      @override     public long getchildid(int groupposition, int childposition) {         return childposition;     }      @override     public view getchildview(int groupposition, final int childposition,             boolean islastchild, view convertview, viewgroup parent) {          navdraweritem child = (navdraweritem) getchild(groupposition, childposition);         /*if (convertview == null)          {             layoutinflater infalinflater = (layoutinflater) this._context.getsystemservice(context.layout_inflater_service);             if(groupposition==0)             {                 convertview = infalinflater.inflate(r.layout.row_selectdevice_listitem, null);             }             else             {                 convertview = infalinflater.inflate(r.layout.row_selectdevice_childlist, null);             }         }*/         if(groupposition==0)         {             layoutinflater infalinflater = (layoutinflater) this._context.getsystemservice(context.layout_inflater_service);             convertview = infalinflater.inflate(r.layout.row_selectdevice_listitem, null);             textview txtlistchild = (textview) convertview.findviewbyid(r.id.label_devicetoselect);             txtlistchild.settext(child.gettitle());         }         else         {             layoutinflater infalinflater = (layoutinflater) this._context.getsystemservice(context.layout_inflater_service);             convertview = infalinflater.inflate(r.layout.row_selectdevice_childlist, null);             expandablelistview explistview = (expandablelistview) convertview.findviewbyid(r.id.list_selectdevice);              explistview.setchilddivider(_context.getresources().getdrawable(r.drawable.unit_cell_line_spacing));             final arraylist<navdraweritem> listdataheader = new arraylist<navdraweritem>();             final hashmap<string, arraylist<navdraweritem>> listdatachild = new hashmap<string, arraylist<navdraweritem>>();             typedarray navmenuicons = _context.getresources().obtaintypedarray(r.array.nav_drawer_icons);                        listdataheader.add(new navdraweritem(child.gettitle(), navmenuicons.getresourceid(1, -1), false));             //prepare subchilds list             arraylist<navdraweritem> subchilds = new arraylist<navdraweritem>();              subchilds.add(new navdraweritem("sub child 1", navmenuicons.getresourceid(1, -1), false));             subchilds.add(new navdraweritem("sub child 2", navmenuicons.getresourceid(1, -1), false));              arraylist<navdraweritem> energychilds = new arraylist<navdraweritem>();              energychilds.add(new navdraweritem("energy monitoring dimmable lamp module", navmenuicons.getresourceid(1, -1), false));             energychilds.add(new navdraweritem("home energy meter", navmenuicons.getresourceid(1, -1), false));             energychilds.add(new navdraweritem("smartswitch", navmenuicons.getresourceid(1, -1), false));              if(child.gettitle().equalsignorecase("energy"))             {                 listdatachild.put(child.gettitle(), energychilds);                  log.e("check subchild", child.gettitle() + energychilds);             }                    listadapter_selectdevicechild listadapter = new listadapter_selectdevicechild(_context, listdataheader, listdatachild);             explistview.setadapter(listadapter);              ////////////////////////////////////////             // listview group click listener             /*explistview.setongroupclicklistener(new ongroupclicklistener() {                 @override                 public boolean ongroupclick(expandablelistview parent, view v,                         int groupposition, long id) {                      toast.maketext(_context.getapplicationcontext(),                      "group clicked " + listdataheader.get(groupposition),                      toast.length_short).show();                      return false;                 }             });             // listview group expanded listener             explistview.setongroupexpandlistener(new ongroupexpandlistener() {                  @override                 public void ongroupexpand(int groupposition) {                     toast.maketext(_context.getapplicationcontext(),                             listdataheader.get(groupposition) + " expanded",                             toast.length_short).show();                     listadapter._listdataheader.get(groupposition).setisselected(true);                     listadapter.notifydatasetchanged();                  }             });             // listview group collasped listener              explistview.setongroupcollapselistener(new ongroupcollapselistener() {                 @override                 public void ongroupcollapse(int groupposition) {                     toast.maketext(_context.getapplicationcontext(),                             listdataheader.get(groupposition) + " collapsed",                             toast.length_short).show();                     listadapter._listdataheader.get(groupposition).setisselected(false);                     listadapter.notifydatasetchanged();                 }             });             // listview on child click listener             explistview.setonchildclicklistener(new onchildclicklistener() {                  @override                 public boolean onchildclick(expandablelistview parent, view v,                         int groupposition, int childposition, long id) {                     // todo auto-generated method stub                     toast.maketext(                             _context.getapplicationcontext(),                             listdataheader.get(groupposition)                                     + " : "                                     + listdatachild.get(                                             listdataheader.get(groupposition)).get(                                             childposition), toast.length_short)                             .show();                     return false;                 }             });*/           }         return convertview;     }       @override     public int getchildrencount(int groupposition) {         string key = this._listdataheader.get(groupposition).gettitle();         return this._listdatachild.get(key).size();     }      @override     public object getgroup(int groupposition) {         return this._listdataheader.get(groupposition);     }      @override     public int getgroupcount() {         return this._listdataheader.size();     }      @override     public long getgroupid(int groupposition) {         return groupposition;     }      @override     public view getgroupview(int groupposition, boolean isexpanded,             view convertview, viewgroup parent) {         navdraweritem header = (navdraweritem) getgroup(groupposition);          if (convertview == null) {             layoutinflater infalinflater = (layoutinflater) this._context                     .getsystemservice(context.layout_inflater_service);             convertview = infalinflater.inflate(r.layout.row_selectdevice_groupitem, null);         }          relativelayout layout_selectdeviceoptions = (relativelayout) convertview.findviewbyid(r.id.layout_selectdeviceoptions);         imageview img_group_items = (imageview) convertview.findviewbyid(r.id.img_group_items);          if(header.getisselected())         {             layout_selectdeviceoptions.setbackgroundcolor(color.parsecolor("#ffffe0"));              int currentapiversion = android.os.build.version.sdk_int;             if (currentapiversion <= android.os.build.version_codes.ice_cream_sandwich_mr1)              {                 img_group_items.setbackgrounddrawable(_context.getresources().getdrawable(r.drawable.cart));             } else {                 img_group_items.setbackground(_context.getresources().getdrawable(r.drawable.cart));             }             //layout_selectdeviceoptions.setbackgroundresource(_context.getresources().getcolor(r.color.yellow));          }         else         {             layout_selectdeviceoptions.setbackground(null);              int currentapiversion = android.os.build.version.sdk_int;             if (currentapiversion <= android.os.build.version_codes.ice_cream_sandwich_mr1)              {                 img_group_items.setbackgrounddrawable(_context.getresources().getdrawable(r.drawable.plus));             } else {                 img_group_items.setbackground(_context.getresources().getdrawable(r.drawable.plus));             }         }         textview lbllistheader = (textview) convertview.findviewbyid(r.id.label_group_items);         lbllistheader.settext(header.gettitle());          return convertview;     }      @override     public boolean hasstableids() {         return false;     }      @override     public boolean ischildselectable(int groupposition, int childposition) {         return true;     }  }  import java.util.arraylist; import java.util.hashmap; import java.util.list;  import com.vera.r.color; import com.vera.navdrawer.navdraweritem; import android.content.context; import android.content.res.typedarray; import android.graphics.color; import android.graphics.typeface; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup; import android.widget.baseexpandablelistadapter; import android.widget.expandablelistview; import android.widget.imageview; import android.widget.relativelayout; import android.widget.textview; import android.widget.expandablelistview.onchildclicklistener; import android.widget.expandablelistview.ongroupclicklistener; import android.widget.expandablelistview.ongroupcollapselistener; import android.widget.expandablelistview.ongroupexpandlistener; import android.widget.toast;  public class listadapter_selectdevicechild extends baseexpandablelistadapter {      private context _context;     public arraylist<navdraweritem> _listdataheader; // header titles     public hashmap<string, arraylist<navdraweritem>> _listdatachild;      public listadapter_selectdevicechild(context context, arraylist<navdraweritem> listdataheader, hashmap<string, arraylist<navdraweritem>> listdatachild) {         this._context = context;         this._listdataheader = listdataheader;          this._listdatachild = listdatachild;      }      @override     public object getchild(int groupposition, int childposititon) {         navdraweritem l = this._listdatachild.get(this._listdataheader.get(groupposition).gettitle()).get(childposititon);         return l;         /*string s = this._listdatachild.get(this._listdataheader.get(groupposition).gettitle()).get(childposititon);         return s;*/     }      @override     public long getchildid(int groupposition, int childposition) {         return childposition;     }      @override     public view getchildview(int groupposition, final int childposition,             boolean islastchild, view convertview, viewgroup parent) {          navdraweritem child = (navdraweritem) getchild(groupposition, childposition);         layoutinflater infalinflater = (layoutinflater) this._context.getsystemservice(context.layout_inflater_service);         convertview = infalinflater.inflate(r.layout.row_selectdevice_listitem, null);         textview txtlistchild = (textview) convertview.findviewbyid(r.id.label_devicetoselect);         txtlistchild.settext(child.gettitle());          return convertview;     }       @override     public int getchildrencount(int groupposition) {         string key = this._listdataheader.get(groupposition).gettitle();         return this._listdatachild.get(key).size();     }      @override     public object getgroup(int groupposition) {         return this._listdataheader.get(groupposition);     }      @override     public int getgroupcount() {         return this._listdataheader.size();     }      @override     public long getgroupid(int groupposition) {         return groupposition;     }      @override     public view getgroupview(int groupposition, boolean isexpanded,             view convertview, viewgroup parent) {         navdraweritem header = (navdraweritem) getgroup(groupposition);          if (convertview == null) {             layoutinflater infalinflater = (layoutinflater) this._context                     .getsystemservice(context.layout_inflater_service);             convertview = infalinflater.inflate(r.layout.row_selectdevice_groupitem, null);         }          relativelayout layout_selectdeviceoptions = (relativelayout) convertview.findviewbyid(r.id.layout_selectdeviceoptions);         imageview img_group_items = (imageview) convertview.findviewbyid(r.id.img_group_items);          if(header.getisselected())         {             layout_selectdeviceoptions.setbackgroundcolor(color.parsecolor("#ffffe0"));              int currentapiversion = android.os.build.version.sdk_int;             if (currentapiversion <= android.os.build.version_codes.ice_cream_sandwich_mr1)              {                 img_group_items.setbackgrounddrawable(_context.getresources().getdrawable(r.drawable.cart));             } else {                 img_group_items.setbackground(_context.getresources().getdrawable(r.drawable.cart));             }             //layout_selectdeviceoptions.setbackgroundresource(_context.getresources().getcolor(r.color.yellow));          }         else         {             layout_selectdeviceoptions.setbackground(null);              int currentapiversion = android.os.build.version.sdk_int;             if (currentapiversion <= android.os.build.version_codes.ice_cream_sandwich_mr1)              {                 img_group_items.setbackgrounddrawable(_context.getresources().getdrawable(r.drawable.plus));             } else {                 img_group_items.setbackground(_context.getresources().getdrawable(r.drawable.plus));             }         }         textview lbllistheader = (textview) convertview.findviewbyid(r.id.label_group_items);         lbllistheader.settext(header.gettitle());          return convertview;     }      @override     public boolean hasstableids() {         return false;     }      @override     public boolean ischildselectable(int groupposition, int childposition) {         return true;     }  } 


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -