expandablelistview - How to make three level expandable List view from JSON in Android? -


hi want create 3 level expandable list view json. have creted expandable list view 2 two level 3 level did not got how please if body don please me complete it. here code have created.

my main activity

string tag="mainactivity"; private expandablelistview expandablelistview; arraylist<string>mainlist =new arraylist<>();; hashmap<string, list<string>>  childcontent = new hashmap<string, list<string>>();  hashmap<string, hashmap<list<string>,list<string>>>  subchildcontent = new  hashmap<string, hashmap<list<string>,list<string>>>(); list<string> childlist; list<string> subchildlist; private list<string> parentheaderinformation; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      new releaseoverviewreleaseasynchtask().execute(); }  @override protected void onresume() {     super.onresume();      expandablelistview = (expandablelistview)findviewbyid(r.id.expandablelistview);      //expandablelistadapter expandablelistviewadapter = new expandablelistadapter(getapplicationcontext(), mainlist, childcontent);     childsubchildexpandablelistadapter adapter=new childsubchildexpandablelistadapter(getapplicationcontext(),mainlist,childlist,childcontent);     expandablelistview.setadapter(adapter); }    class releaseoverviewreleaseasynchtask extends asynctask<void,void,void> {       @override     protected void onpreexecute() {         super.onpreexecute();     }      @override     protected void doinbackground(void... params) {         string jsonstr = util.loadjsonfromasset(mainactivity.this,"release.json");         if (jsonstr != null) {             try {                 jsonarray array = new jsonarray(jsonstr);                  (int = 0; < array.length(); i++) {                      jsonobject jo_object = array.getjsonobject(i);                     childlist= new arraylist<string>();                     subchildlist= new arraylist<string>();                     string release= jo_object.get("release").tostring();                     mainlist.add(jo_object.get("release").tostring());                     log.i("main release",release);                     jsonarray jsonarraydetails=jo_object.getjsonarray("details");                     if (!jsonarraydetails.isnull(i)){                         jsonobject jo_object1 = jsonarraydetails.getjsonobject(i);                          string builddate=  jo_object1.get("build date").tostring();                         log.i(tag,builddate);                         string deploydate= jo_object1.get("deploy date").tostring();                         log.i(tag,deploydate);                         string respindate= jo_object1.get("respin date").tostring();                         log.i(tag,respindate);                         string releaselead= jo_object1.get("release lead").tostring();                         log.i(tag,releaselead);                         string engineerlead= jo_object1.get("engineering lead").tostring();                         log.i(tag,engineerlead);                         string testlead=jo_object1.get("test lead").tostring();                         log.i(tag,testlead);                       }                     jsonarray childarray=jo_object.getjsonarray("children");                      (int i_child = 0; i_child < childarray.length(); i_child++) {                         jsonobject jo_objectchild = childarray.getjsonobject(i_child);                          childlist.add(jo_objectchild.get("release").tostring());                         log.i("child release",jo_objectchild.get("release").tostring());                          jsonarray subchildarray=jo_objectchild.getjsonarray("children");                          (int i_subchild=0;i_subchild<=subchildarray.length();i_subchild++){                             if (!subchildarray.isnull(i_subchild)){                                 jsonobject jo_objectsubchild = subchildarray.getjsonobject(i_subchild);                                 log.i("sub release",jo_objectsubchild.get("release").tostring());                                 subchildlist.add(jo_objectsubchild.get("release").tostring());                             }                              /*jsonobject jo_objectsubchild = subchildarray.getjsonobject(i_subchild);                            */                         }                        }                     childcontent.put(mainlist.get(i),subchildlist);                 }               }             catch (jsonexception e) {                 e.printstacktrace();             }         }         else{             //  log.e(tag, "couldn't json server.");             runonuithread(new runnable() {                 @override                 public void run() {                     toast.maketext(getapplicationcontext(),                             "couldn't json server. check logcat possible errors!",                             toast.length_long)                             .show();                 }             });          }         return null;     } 

my parent expandable list view is

public class expandablelistadapter extends baseexpandablelistadapter { private context context; private list<string> parentdatasource; private hashmap<string, list<string>> childdatasource;  private hashmap<string, list<string>> subchilddatasource;  public expandablelistadapter(context context, list<string> childparent, hashmap<string, list<string>> child){      this.context = context;      this.parentdatasource = childparent;      this.childdatasource = child; } @override public int getgroupcount() {     return this.parentdatasource.size(); }  @override public int getchildrencount(int groupposition) {     return  this.childdatasource.get(this.parentdatasource.get(groupposition)).size(); }  @override public object getgroup(int groupposition) {     return parentdatasource.get(groupposition);  }  @override public object getchild(int groupposition, int childposition) {     return this.childdatasource.get(parentdatasource.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 false; }  @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) {     view view = convertview;     if(view == null){          layoutinflater inflater = (layoutinflater)this.context.getsystemservice(context.layout_inflater_service);          view = inflater.inflate(r.layout.parentlayout, parent, false);      }     string parentheader = (string)getgroup(groupposition);      textview parentitem = (textview)view.findviewbyid(r.id.parent_layout);      parentitem.settext(parentheader);     notifydatasetchanged();     return view; }  @override public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup parent) {     view view = convertview;      if(view == null){          layoutinflater inflater = (layoutinflater)this.context.getsystemservice(context.layout_inflater_service);          view = inflater.inflate(r.layout.childlayout, parent, false);      }     string childname = (string)getchild(groupposition, childposition);      textview childitem = (textview)view.findviewbyid(r.id.child_layout);      childitem.settext(childname);     notifydatasetchanged();     return view; }  @override public boolean ischildselectable(int groupposition, int childposition) {     return true; } 

here expandable list 3 level not working me

public class childsubchildexpandablelistadapter extends  baseexpandablelistadapter{  context context; hashmap<string, list<string>> childdata;  private list<string> parentdatasource; list<string> secondlevel; private hashmap<string, list<string>> childdatasource;  public childsubchildexpandablelistadapter(context context, list<string> parent, list<string> secondlevel, hashmap<string, list<string>> data) {     this.context = context;      this.parentdatasource = parent;      this.secondlevel = secondlevel;      this.childdata = data;   } @override public int getgroupcount() {    return this.parentdatasource.size(); }  @override public int getchildrencount(int groupposition) {     return 1; }  @override public object getgroup(int i) {     return i; }  @override public object getchild(int i, int i1) {     return i1; }  @override public long getgroupid(int i) {     return i; }  @override public long getchildid(int i, int i1) {     return i1; }  @override public boolean hasstableids() {     return true; }  @override public view getgroupview(int groupposition, boolean b, view convertview, viewgroup viewgroup) {     view view = convertview;     layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);     convertview = inflater.inflate(r.layout.parentlayout, null);     textview text = (textview) convertview.findviewbyid(r.id.parent_layout);     text.settext(this.parentdatasource.get(groupposition));     return convertview; }  @override public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup group) {     final secondlevelexpandablelistview secondlevelelv = new secondlevelexpandablelistview(context);      string headers =secondlevel.get(groupposition);     list<string> header=new arraylist<>();     header.add(headers);     list<list<string>> childdata = new arraylist<>();    hashmap<string, list<string>> secondleveldata= (hashmap<string, list<string>>) childdata.get(groupposition);     for(string key : secondleveldata.keyset())     {           childdata.add(secondleveldata.get(key));      }      secondlevelelv.setadapter(new expandablelistadapter(context, header,secondleveldata));      secondlevelelv.setgroupindicator(null);      secondlevelelv.setongroupexpandlistener(new expandablelistview.ongroupexpandlistener() {         int previousgroup = -1;          @override         public void ongroupexpand(int groupposition) {             if(groupposition != previousgroup)                 secondlevelelv.collapsegroup(previousgroup);             previousgroup = groupposition;         }     });     return secondlevelelv; }  @override public boolean ischildselectable(int i, int i1) {     return true; } 

}

here second level expandable list view

  public class secondlevelexpandablelistview extends expandablelistview   {      public secondlevelexpandablelistview(context context) {         super(context);     }      protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {         //999999 size in pixels. expandablelistview requires maximum height in order measurement calculations.          heightmeasurespec = measurespec.makemeasurespec(999999, measurespec.at_most);         super.onmeasure(widthmeasurespec, heightmeasurespec);     } 

hi friends please me create 3 level expandable. above code works if use expandablelistadapter. in above code have used childsubchildadapter 3 level not working

i want add check box in each element of lists , if select child parent should selected

here json

{ "release": "16.1", "details": [], "children": [   {     "release": "16.1r3",     "details": [       {         "build date": "",         "deploy date": "",         "respin date": "",         "release lead": "jl",         "engineering lead": "lg",         "test lead": "dl"       }     ],     "children": [       {         "release": "16.1r3-s5",         "details": [           {             "build date": "2017-08-17",             "deploy date": "2017-08-25",             "respin date": "",             "release lead": "jk",             "engineering lead": "ly",             "test lead": "fd"           }         ]       }     ]   } 

please me in problem. doing type of work first time.

thanks in advance

my suggestion use recycler view instead of expandable list view ,because in case of large data expandable list view create issue ,specially in case of 3 level expandable list view.

and create model class each level of list have boolean value checkbox click.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -