java - How to get children elements dynamically within expandablelistview by clicking parent node in android -
java - How to get children elements dynamically within expandablelistview by clicking parent node in android -
i new android explain how create childlist dynamic clicking parent?
my problem: have static parent in expandablelistview. intention is, when select parent see child, kid come dynamically form info base of operations , navigable (i want see more detail or go different page.)
i done static kid in 3 steps.
create xml file expandablelistview. on main java phone call adapter bind adapter expandablelistview. create custom adapter.the adapter following:
package com.example.eschool_only_accrdion_straggle;  import android.r.color; import android.content.context; import android.graphics.color; import android.view.view; import android.view.viewgroup; import android.widget.baseexpandablelistadapter; import android.widget.textview;  public class my_custom_adapter extends baseexpandablelistadapter {      private context context;      string [] parentlist={"summer fruit", "winter fruit", "hard fruit", "watery fruit"};     // string [][] childlist={{"lychy", "mango"},{"banana"},{"pomy granade"},{"pani fruit"}};       public my_custom_adapter(context context) {         this.context = context;     }      // in here 1st parameter parent , 2nd 1  kid      @override     public object getchild(int groupposition, int childposition) {          // todo auto-generated method stub          homecoming null;     }      @override     public long getchildid(int groupposition, int childposition) {         // todo auto-generated method stub          homecoming 0;     }      @override     public view getchildview(int groupposition, int childposition,              boolean arg2, view arg3, viewgroup arg4) {          textview txtv_child=new textview(context);         txtv_child.settext(childlist[groupposition][childposition]);         txtv_child.setpadding(35, 0, 0, 0);         txtv_child.settextcolor(color.cyan);         txtv_child.settextsize(17);          homecoming txtv_child;     }      @override     public int getchildrencount(int groupposition) {           homecoming childlist[groupposition].length;     }      @override     public object getgroup(int groupposition) {           homecoming groupposition;     }      @override     public int getgroupcount() {         // todo auto-generated method stub          homecoming parentlist.length;     }      @override     public long getgroupid(int groupposition) {         // todo auto-generated method stub          homecoming groupposition;     }      @override     public view getgroupview(int groupposition, boolean childposition, view arg2, viewgroup arg3) {         textview txtv_parent=new textview(context);         txtv_parent.settext(parentlist[groupposition]);         txtv_parent.setpadding(5, 5, 0, 5);         txtv_parent.settextcolor(color.magenta);         txtv_parent.settextsize(25);          homecoming txtv_parent;     }      @override     public boolean hasstableids() {         // todo auto-generated method stub          homecoming false;     }      @override     public boolean ischildselectable(int groupposition, int childposition) {         // todo auto-generated method stub          homecoming true;     }  }                                     
create activity extending "expandablelistactivity", follow illustration tutorial
initialize data
private arraylist<string> groups = new arraylist<string>() ; private arraylist<arraylist<string>> children;  private newadapter mnewadapter = null;  public void oncreate(bundle savedinstancestate) {      // ....     groups.add("summer fruit");     groups.add("winter fruit");     groups.add("hard fruit");     groups.add("watery fruit");      children = new arraylist<arraylist<string>>();      arraylist<string> = new arraylist<string>();     a.add("lychy");     a.add("mango");     children.add(a);      = new arraylist<string>();     a.add("banana");     children.add(a);      = new arraylist<string>();     a.add("pomy granade");     children.add(a);       = new arraylist<string>();     a.add("pani fruit");     children.add(a);      mnewadapter = new newadapter(groups, children);     mnewadapter.setinflater((layoutinflater) getsystemservice(context.layout_inflater_service),this);     getexpandablelistview().setadapter(mnewadapter);     int cpt = mnewadapter.getgroupcount();     for(int = 0; < cpt; i++ ){         getexpandablelistview().expandgroup(i);     } }    then sure overwrite next method activity
@override public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) {     // here need when  kid selected      homecoming true; }    add add together adapter
class newadapter extends baseexpandablelistadapter{      public layoutinflater minflater;     public activity activity;     public arraylist<string> groups;     public arraylist<arraylist<string>> points;      public newadapter(arraylist<string> groups, arraylist<arraylist<string>> points){         this.groups = groups;         this.points = points;     }      public void setinflater(layoutinflater minflater, activity act) {         this.minflater = minflater;         activity = act;     }      @override     public void notifydatasetchanged() {         super.notifydatasetchanged();     }      @override     public object getchild(int groupposition, int childposition) {          homecoming null;     }      @override     public long getchildid(int groupposition, int childposition) {          homecoming 0;     }      @override     public int getchildrencount(int groupposition) {          homecoming ((arraylist<string>) points.get(groupposition)).size();     }      @override     public object getgroup(int groupposition) {          homecoming groups.get(groupposition);     }      @override     public int getgroupcount() {          homecoming groups.size();     }      @override     public void ongroupcollapsed(int groupposition) {         super.ongroupcollapsed(groupposition);     }      @override     public long getgroupid(int groupposition) {          homecoming 0;     }      @override     public view getgroupview(int groupposition, boolean childposition, view arg2, viewgroup arg3) {         // ...          homecoming v;     }      @override     public boolean hasstableids() {          homecoming false;     }      @override     public boolean ischildselectable(int groupposition, int childposition) {          homecoming true;     }      @override     public view getchildview(int groupposition, final int childposition, boolean islastchild, view v, viewgroup parent) {         // ....          homecoming v;     } }    within adapter sure have ischildselectable(int groupposition, int childposition) returning "true".
 java android expandablelistview 
 
Comments
Post a Comment