java - Implementing Expandable ListView in fragment in Android Studio -


i trying put expandable listview inside fragment, each item of list can drop down , show more text below it. tried multiple way didn't succeed. no error or warnings, when click on fragment mobile app quit.

the fragment called projects. want contains list of titles of projects, each of them can drop down show details. code here:

fragment_project.java

import android.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.expandablelistadapter; import android.widget.expandablelistview;  import java.util.arraylist; import java.util.hashmap; import java.util.list; import java.util.map;    public class fragment_project extends fragment {      expandablelistview expandablelistview;     expandablelistadapter expandablelistadapter;      list<string> titles;     map<string, string> texts;      @override         public view oncreateview(layoutinflater inflater, viewgroup container,                                  bundle savedinstancestate) {                // inflate layout fragment             return init(inflater.inflate(r.layout.content_projects, container, false));         }          private view init(view inflate) {             expandablelistview = (expandablelistview) inflate.findviewbyid(r.id.expandable_list_view);             fill_data();              expandablelistadapter = new fragment_project_exp_list_adapter(inflate, titles, texts);             expandablelistview.setadapter(expandablelistadapter);               return expandablelistview;         }      public void fill_data() {          titles = new arraylist<>();         texts = new hashmap<>();          string title1 = getstring(r.string.title_android_project);         string title2 = getstring(r.string.title_html5_project);          titles.add(title1);         titles.add(title2);          string text1 = getstring(r.string.content_android_project);         string text2 = getstring(r.string.content_html5_project);          texts.put(title1, text1);         texts.put(title2, text2);     }        } 

fragment_project_exp_list_adapter.java

import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseexpandablelistadapter; import android.widget.textview;  import java.util.list; import java.util.map;    public class fragment_project_exp_list_adapter extends baseexpandablelistadapter {      view inflate;     list<string> titles;     map<string, string> texts;      public fragment_project_exp_list_adapter(view inflate, list<string> titles, map<string, string> texts) {         this.inflate = inflate;         this.titles = titles;         this.texts = texts;     }      @override     public int getgroupcount() {         return titles.size();     }      @override     public int getchildrencount(int i) {         return 1;   // hashmap string string, not string multiple strings, children count each group 1.     }      @override     public object getgroup(int i) {         return titles.get(i);     }      @override     public object getchild(int i, int i1) {         return texts.get(i1);     }      @override     public long getgroupid(int i) {         return i;     }      @override     public long getchildid(int i, int i1) {         return i1;     }      @override     public boolean hasstableids() {         return false;     }      @override     public view getgroupview(int i, boolean b, view view, viewgroup viewgroup) {          string title = (string) getgroup(i);          if (view == null){              view = inflate.findviewbyid(r.id.project_titles);         }          return view;     }        @override     public view getchildview(int i, int i1, boolean b, view view, viewgroup viewgroup) {          string text = (string) getchild(i, i1);          if (view == null){              view = inflate.findviewbyid(r.id.project_texts);         }           return view;     }      @override     public boolean ischildselectable(int i, int i1) {         return false;     } } 

i feel need in public view oncreateview inside "fragment_project.java" file not sure how. appreciated. thank you!


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -