Android ExpandableListview all child item in every group -


i create expandablelistview in android. use custom adapter child item in every single group.

result want :

[ first ]       [ second ]       [ third ]  - aaa           - ddd           - ggg - bbb           - eee           - hhh - ccc           - fff           - iii 

('first', 'second', , 'third' expandable list group name / , other child item name)

but list show :

[ first ]       [ second ]       [ third ]  - aaa           - aaa           - aaa - bbb           - bbb           - bbb - ccc           - ccc           - ccc - ddd           - ddd           - ddd - eee           - eee           - eee - fff           - fff           - fff - ggg           - ggg           - ggg - hhh           - hhh           - hhh - iii           - iii           - iii 

screenshot : (i changed group name)

enter image description here

this code :

//expandablelist private expandablelistview mpastmedallist;  //listview adapter private arraylist<string> mgrouplist = new arraylist<>(); private arraylist<object> mchildlist = null; private arraylist<string> mchildlistcontent = new arraylist<>();  private void setlist(){     setgroupdata();     setchildgroupdata();      mpastmedallist.setadapter(new baseexpandableadapter(getactivity(), mgrouplist, mchildlist));     mpastmedallist.expandgroup(0); //default expand      //click event     mpastmedallist.setongroupclicklistener(new expandablelistview.ongroupclicklistener() {         @override         public boolean ongroupclick(expandablelistview parent, view v, int groupposition, long id) {             setexpandablelistviewheight(parent, groupposition);             return false;         }     }); }  private void setgroupdata() {     mgrouplist.add("first");     mgrouplist.add("second");     mgrouplist.add("third"); }  private void setchildgroupdata() {     mchildlist = new arraylist<>();     mchildlistcontent.add("aaa");     mchildlistcontent.add("bbb");     mchildlistcontent.add("ccc");     mchildlist.add(mchildlistcontent);      mchildlist = new arraylist<>();     mchildlistcontent.add("ddd");     mchildlistcontent.add("eee");     mchildlistcontent.add("fff");     mchildlist.add(mchildlistcontent);      mchildlist = new arraylist<>();     mchildlistcontent.add("ggg");     mchildlistcontent.add("hhh");     mchildlistcontent.add("iii");     mchildlist.add(mchildlistcontent); } 

and adapter source:

public class baseexpandableadapter extends baseexpandablelistadapter {     private arraylist<string> grouplist = null;     private arraylist<object> childlist = null;     private layoutinflater inflater = null;     private viewholder viewholder = null;      public baseexpandableadapter(context c, arraylist<string> grouplist, arraylist<object> childlist){         super();         this.inflater = layoutinflater.from(c);         this.grouplist = grouplist;         this.childlist = childlist;     }      //return group size     @override     public int getgroupcount() {         return grouplist.size();     }      //return child view size     @override     public int getchildrencount(int groupposition) {         return ((arraylist<string>) childlist.get(groupposition)).size();     }      //return group position      @override     public string getgroup(int groupposition) {         return grouplist.get(groupposition);     }      //return child view     @override     public string getchild(int groupposition, int childposition) {         return ((arraylist<string>)childlist.get(groupposition)).get(childposition);     }      //return group id     @override     public long getgroupid(int groupposition) {         return groupposition;     }      //return child view id     @override     public long getchildid(int groupposition, int childposition) {         return childposition;     }      @override     public boolean hasstableids() {         return true;     }      //each group view row     @override     public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) {         view view = convertview;          if(view == null){             viewholder = new viewholder();             view = inflater.inflate(r.layout.rio2016_sports_olympic_header, null);             viewholder.header = (textview) view.findviewbyid(r.id.sports_olympic_list_header);             viewholder.drawer = (imageview) view.findviewbyid(r.id.sports_olympic_list_drawer);             view.settag(viewholder);         } else {             viewholder = (viewholder)view.gettag();         }          //change icon when open or close         if(isexpanded){ //open             viewholder.drawer.setimageresource(r.drawable.rio2016_sports_olympic_detail_drawer_up);         }else{ //close             viewholder.drawer.setimageresource(r.drawable.rio2016_sports_olympic_detail_drawer_down);         }          viewholder.header.settext(getgroup(groupposition));          return view;     }      //return child view     @override     public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup parent) {         view view = convertview;          if(view == null){             viewholder = new viewholder();             view = inflater.inflate(r.layout.rio2016_sports_olympic_item, null);             viewholder.medal = (imageview) view.findviewbyid(r.id.sports_olympic_list_medal);             viewholder.flag = (imageview) view.findviewbyid(r.id.sports_olympic_list_flag);             viewholder.countries = (textview) view.findviewbyid(r.id.sports_olympic_list_countries);             viewholder.name = (textview) view.findviewbyid(r.id.sports_olympic_list_name);             view.settag(viewholder);         } else {             viewholder = (viewholder)view.gettag();         }          viewholder.medal.setimageresource(r.drawable.rio2016_sports_olympic_detail_medal);         viewholder.flag.setimageresource(r.drawable.rio2016_sports_olympic_detail_flag);         viewholder.countries.settext("kor");         viewholder.name.settext(getchild(groupposition, childposition));          return view;     }      //     @override     public boolean ischildselectable(int groupposition, int childposition) {         return true;     }      class viewholder {         //header         private textview header;         private imageview drawer;          //item         private imageview medal;         private imageview flag;         private textview countries;         private textview name;     } } 

i wonder why don't every child item in correct each group? please me! thanks, :)

inside setchildgroupdata() function using same mchildlistcontent variable instead of creating new 1 each of three. should ->

    mchildlist = new arraylist<>();     mchildlistcontent = new arraylist<>();     mchildlistcontent.add("aaa");     mchildlistcontent.add("bbb");     mchildlistcontent.add("ccc");     mchildlist.add(mchildlistcontent);      mchildlist = new arraylist<>();     mchildlistcontent = new arraylist<>();     mchildlistcontent.add("ddd");     mchildlistcontent.add("eee");     mchildlistcontent.add("fff");     mchildlist.add(mchildlistcontent);      mchildlist = new arraylist<>();     mchildlistcontent = new arraylist<>();     mchildlistcontent.add("ggg");     mchildlistcontent.add("hhh");     mchildlistcontent.add("iii");     mchildlist.add(mchildlistcontent); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -