java - Update ExpandableListView -


i don't know how update expandablelistview, not sure should write in onactivityresult. want change customexpandablelistadapter.getdata() thing.getmaps(); want learn how it.

main activity

    // main activity  package com.thehuntestshadow.laken;  import android.app.activity; import android.support.design.widget.floatingactionbutton; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.baseadapter; import android.widget.button; import android.widget.expandablelistadapter; import android.widget.listadapter; import android.widget.listview; import android.widget.arrayadapter; import android.widget.toast; import android.content.intent; import android.widget.imagebutton; import android.view.view.onclicklistener; import android.widget.expandablelistview; import android.widget.expandablelistview.onchildclicklistener; import android.widget.expandablelistview.ongroupclicklistener; import android.widget.expandablelistview.ongroupcollapselistener; import android.widget.expandablelistview.ongroupexpandlistener;  import java.util.arraylist; import java.util.hashmap; import java.util.list;  public class mainactivity extends appcompatactivity{     mydbhandler dbhandler =new mydbhandler(this,null,null,1);     mydbmanager dbmanager = new mydbmanager(this,null,null,1);         expandablelistview expandablelistview;     expandablelistadapter expandablelistadapter;      list<string> expandablelisttitle;     hashmap<string, list<string>> expandablelistdetail;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         expandablelistview = (expandablelistview) findviewbyid(r.id.expandablelistview);         expandablelistdetail = expandablelistdatapump.getdata();         expandablelisttitle = new arraylist<string>(expandablelistdetail.keyset());         expandablelistadapter = new customexpandablelistadapter(this, expandablelisttitle, expandablelistdetail);         expandablelistview.setadapter(expandablelistadapter);         expandablelistview.setongroupexpandlistener(new expandablelistview.ongroupexpandlistener() {              @override             public void ongroupexpand(int groupposition) {                 toast.maketext(getapplicationcontext(),                         expandablelisttitle.get(groupposition) + " list expanded.",                         toast.length_short).show();              }         });          expandablelistview.setongroupcollapselistener(new expandablelistview.ongroupcollapselistener() {              @override             public void ongroupcollapse(int groupposition) {                 toast.maketext(getapplicationcontext(),                         expandablelisttitle.get(groupposition) + " list collapsed.",                         toast.length_short).show();              }         });          expandablelistview.setonchildclicklistener(new expandablelistview.onchildclicklistener() {             @override             public boolean onchildclick(expandablelistview parent, view v,                                         int groupposition, int childposition, long id) {                 toast.maketext(                         getapplicationcontext(),                         expandablelisttitle.get(groupposition)                                 + " -> "                                 + expandablelistdetail.get(                                 expandablelisttitle.get(groupposition)).get(                                 childposition), toast.length_short                 ).show();                 return false;             }         });         }       public void onclick(view view) {         intent = new intent(this, add_activity.class);         startactivityforresult(i, 1);     }            @override     protected void onactivityresult(int requestcode, int resultcode, intent meow) {          if (requestcode == 1) {             if(resultcode == activity.result_ok){                 expandablelistdetail= thing.getmaps();                  }             if (resultcode == activity.result_canceled) {                 //write code if there's no result             }         }     }//onactivityresult         } 

customexpandablelistadapter

package com.thehuntestshadow.laken;  /**  * created thehuntestshadow on 10/11/2016.  */  import java.util.hashmap; import java.util.list; import android.content.context; import android.graphics.typeface; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseexpandablelistadapter; import android.widget.textview;  public class customexpandablelistadapter extends baseexpandablelistadapter {      private context context;     private list<string> expandablelisttitle;     private hashmap<string, list<string>> expandablelistdetail;      public customexpandablelistadapter(context context, list<string> expandablelisttitle,                                        hashmap<string, list<string>> expandablelistdetail) {         this.context = context;         this.expandablelisttitle = expandablelisttitle;         this.expandablelistdetail = expandablelistdetail;     }      @override     public object getchild(int listposition, int expandedlistposition) {         return this.expandablelistdetail.get(this.expandablelisttitle.get(listposition))                 .get(expandedlistposition);     }      @override     public long getchildid(int listposition, int expandedlistposition) {         return expandedlistposition;     }      @override     public view getchildview(int listposition, final int expandedlistposition,                              boolean islastchild, view convertview, viewgroup parent) {         final string expandedlisttext = (string) getchild(listposition, expandedlistposition);         if (convertview == null) {             layoutinflater layoutinflater = (layoutinflater) this.context                     .getsystemservice(context.layout_inflater_service);             convertview = layoutinflater.inflate(r.layout.list_item, null);         }         textview expandedlisttextview = (textview) convertview                 .findviewbyid(r.id.expandedlistitem);         expandedlisttextview.settext(expandedlisttext);         return convertview;     }      @override     public int getchildrencount(int listposition) {         return this.expandablelistdetail.get(this.expandablelisttitle.get(listposition))                 .size();     }      @override     public object getgroup(int listposition) {         return this.expandablelisttitle.get(listposition);     }      @override     public int getgroupcount() {         return this.expandablelisttitle.size();     }      @override     public long getgroupid(int listposition) {         return listposition;     }      @override     public view getgroupview(int listposition, boolean isexpanded,                              view convertview, viewgroup parent) {         string listtitle = (string) getgroup(listposition);         if (convertview == null) {             layoutinflater layoutinflater = (layoutinflater) this.context.                     getsystemservice(context.layout_inflater_service);             convertview = layoutinflater.inflate(r.layout.list_group, null);         }         textview listtitletextview = (textview) convertview                 .findviewbyid(r.id.listtitle);         listtitletextview.settypeface(null, typeface.bold);         listtitletextview.settext(listtitle);         return convertview;     }    /* public void setnewitems(list<string> listdataheader,hashmap<string, list<string>> listchilddata) {        // this.expandablelisttitle = listdataheader;         // this.expandablelistdetail = listchilddata;         notifydatasetchanged();     }     */      public void  renew (int x)     {         notifydatasetchanged();     }      @override     public boolean hasstableids() {         return false;     }      @override     public boolean ischildselectable(int listposition, int expandedlistposition) {         return true;     } } 

expandablelistdatapump

package com.thehuntestshadow.laken;  /**  * created thehuntestshadow on 10/11/2016.  */  import java.util.arraylist; import java.util.hashmap; import java.util.list;  public class expandablelistdatapump {     public static hashmap<string, list<string>> getdata() {         hashmap<string, list<string>> expandablelistdetail = new hashmap<string, list<string>>();          list<string> cricket = new arraylist<string>();         cricket.add("india");         cricket.add("pakistan");         cricket.add("australia");         cricket.add("england");         cricket.add("south africa");          list<string> football = new arraylist<string>();         football.add("brazil");         football.add("spain");         football.add("germany");         football.add("netherlands");         football.add("italy");          list<string> basketball = new arraylist<string>();         basketball.add("united states");         basketball.add("spain");         basketball.add("argentina");         basketball.add("france");         basketball.add("russia");          expandablelistdetail.put("cricket teams", cricket);         expandablelistdetail.put("football teams", football);         expandablelistdetail.put("basketball teams", basketball);         return expandablelistdetail;     } } 

thing

package com.thehuntestshadow.laken;  import java.util.arraylist; import java.util.hashmap; import java.util.list;  /**  * created thehuntestshadow on 10/11/2016.  */  public class thing {     public static hashmap<string, list<string>> getmaps() {         hashmap<string, list<string>> expandablelistdetail = new hashmap<string, list<string>>();          list<string> cricket = new arraylist<string>();         cricket.add("taco");         cricket.add("pakistan");         cricket.add("meow");         cricket.add("england");         cricket.add("brazil");          list<string> football = new arraylist<string>();         football.add("blah");         football.add("spain");         football.add("hg");         football.add("hgkhuh");         football.add("italy");          list<string> basketball = new arraylist<string>();         basketball.add("united states");         basketball.add("spein");         basketball.add("ioj");         basketball.add("hg");         basketball.add("russia");          expandablelistdetail.put("cricket teams", cricket);         expandablelistdetail.put("football teams", football);         expandablelistdetail.put("basketball teams", basketball);         return expandablelistdetail;     } } 

thanks!


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -