java - Unable to expand a ExpandableListView in Android -


[edit]- changing question framing: how use android expandablelistview inside scrollview?

i implementing expandablelistview in android. whenever click on arrow expand i.e calling setongroupexpandlistener. list expands inside group itself. want below it. attaching code .

drawable_list_group.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical"     android:padding="8dp"     android:background="@color/grey_transparent">       <textview         android:id="@+id/lbllistheader"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:paddingleft="?android:attr/expandablelistpreferreditempaddingleft"         android:textsize="17dp"         android:textcolor="@color/primary_dark_material_dark" />  </linearlayout> 

drawable_list_item.xml

 <?xml version="1.0" encoding="utf-8"?>     <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical" >          <textview             android:id="@+id/lbllistitem"             android:layout_width="fill_parent"             android:layout_height="match_parent"             android:textsize="25sp"             android:textcolor="@color/highlighted_text_material_light"             android:paddingtop="5dp"             android:paddingbottom="5dp"             android:paddingleft="?android:attr/expandablelistpreferredchildpaddingleft" />      </linearlayout> 

preferences_content.xml(not start)

        <linearlayout             android:layout_width="match_parent"             android:id="@+id/cuisine_preference_linear_layout"             android:layout_height="match_parent"             android:layout_margintop="@dimen/component_margin"             android:orientation="vertical">              <textview                 android:id="@+id/cuisine_preference_label"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_margintop="@dimen/component_margin"                 android:gravity="left"                 android:paddingleft="@dimen/component_margin"                 android:text="cuisines"                 android:textstyle="bold"                 android:textsize="@dimen/subheading_text_size" />               <textview                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_margintop="@dimen/component_margin"                 android:gravity="left"                 android:paddingleft="@dimen/component_margin"                 android:text="choose 3 favourite cuisines:"                 android:textsize="@dimen/subheading_text_size" />             <view                 android:layout_width="match_parent"                 android:layout_height="@dimen/horizontal_line"                 android:layout_marginleft="@dimen/table_row_padding"                 android:layout_marginright="@dimen/table_row_padding"                 android:layout_margintop="@dimen/component_margin"                 android:background="@color/whitegrey"                 android:layout_marginbottom="30dp"/>              <expandablelistview                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:id="@+id/lvexp">              </expandablelistview>            </linearlayout> 

expandablelistadapter.java

package com.fonduetech.cravy.adapter;  import android.widget.baseexpandablelistadapter; 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.textview;  import com.fonduetech.cravy.r;  /**  * created admin on 05-aug-15.  */ public class expandablelistadapter extends baseexpandablelistadapter {           private context _context;         private list<string> _listdataheader; // header titles         // child data in format of header title, child title         private hashmap<string, list<string>> _listdatachild;          public expandablelistadapter(context context, list<string> listdataheader,                                      hashmap<string, list<string>> listchilddata) {             this._context = context;             this._listdataheader = listdataheader;             this._listdatachild = listchilddata;         }          @override         public object getchild(int groupposition, int childposititon) {             return this._listdatachild.get(this._listdataheader.get(groupposition))                     .get(childposititon);         }          @override         public long getchildid(int groupposition, int childposition) {             return childposition;         }          @override         public view getchildview(int groupposition, final int childposition,                                  boolean islastchild, view convertview, viewgroup parent) {              final string childtext = (string) getchild(groupposition, childposition);              if (convertview == null) {                 layoutinflater infalinflater = (layoutinflater) this._context                         .getsystemservice(context.layout_inflater_service);                 convertview = infalinflater.inflate(r.layout.drawable_list_item, null);             }              textview txtlistchild = (textview) convertview                     .findviewbyid(r.id.lbllistitem);              txtlistchild.settext(childtext);             return convertview;         }          @override         public int getchildrencount(int groupposition) {             return this._listdatachild.get(this._listdataheader.get(groupposition))                     .size();         }          @override         public object getgroup(int groupposition) {             return this._listdataheader.get(groupposition);         }          @override         public int getgroupcount() {             return this._listdataheader.size();         }          @override         public long getgroupid(int groupposition) {             return groupposition;         }          @override         public view getgroupview(int groupposition, boolean isexpanded,                                  view convertview, viewgroup parent) {             string headertitle = (string) getgroup(groupposition);             if (convertview == null) {                 layoutinflater infalinflater = (layoutinflater) this._context                         .getsystemservice(context.layout_inflater_service);                 convertview = infalinflater.inflate(r.layout.drawable_list_group, null);             }              textview lbllistheader = (textview) convertview                     .findviewbyid(r.id.lbllistheader);             lbllistheader.settypeface(null, typeface.bold);             lbllistheader.settext(headertitle);              return convertview;         }          @override         public boolean hasstableids() {             return false;         }          @override         public boolean ischildselectable(int groupposition, int childposition) {             return true;         }     } 

preferenceactivity.java

package com.fonduetech.cravy;  import android.content.intent; import android.content.res.configuration; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.os.bundle; import android.support.design.widget.collapsingtoolbarlayout; import android.support.design.widget.coordinatorlayout; import android.support.v4.widget.drawerlayout; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.compoundbutton; import android.widget.expandablelistview; import android.widget.imageview; import android.widget.toast; import android.widget.togglebutton;  import com.fonduetech.cravy.adapter.expandablelistadapter;  import java.util.arraylist; import java.util.hashmap; import java.util.list;  import android.widget.expandablelistview.onchildclicklistener; import android.widget.expandablelistview.ongroupcollapselistener; import android.widget.expandablelistview.ongroupexpandlistener;  public class preferenceactivity extends appcompatactivity {      expandablelistadapter listadapter;     expandablelistview explistview;     list<string> listdataheader;     hashmap<string, list<string>> listdatachild;    protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_preference);          util.overridefonts(preferenceactivity.this, findviewbyid(r.id.drawerlayout));    // listview         explistview = (expandablelistview) findviewbyid(r.id.lvexp);          // preparing list data         preparelistdata();          listadapter = new expandablelistadapter(this, listdataheader, listdatachild);          // setting list adapter         explistview.setadapter(listadapter);          explistview.setonchildclicklistener(new onchildclicklistener() {              @override             public boolean onchildclick(expandablelistview parent, view v,                                         int groupposition, int childposition, long id) {                 toast.maketext(                         getapplicationcontext(),                         listdataheader.get(groupposition)                                 + " : "                                 + listdatachild.get(                                 listdataheader.get(groupposition)).get(                                 childposition), toast.length_short)                         .show();                 return false;             }         });          // listview group expanded listener ongroupexpandlistener         explistview.setongroupexpandlistener(new ongroupexpandlistener() {              @override             public void ongroupexpand(int groupposition) {                 toast.maketext(getapplicationcontext(),                         listdataheader.get(groupposition) + " expanded",                         toast.length_short).show();             }         });          // listview group collasped listener         explistview.setongroupcollapselistener(new ongroupcollapselistener() {              @override             public void ongroupcollapse(int groupposition) {                 toast.maketext(getapplicationcontext(),                         listdataheader.get(groupposition) + " collapsed",                         toast.length_short).show();              }         });          // listview on child click listener         explistview.setonchildclicklistener(new onchildclicklistener() {              @override             public boolean onchildclick(expandablelistview parent, view v,                                         int groupposition, int childposition, long id) {                 // todo auto-generated method stub                 toast.maketext(                         getapplicationcontext(),                         listdataheader.get(groupposition)                                 + " : "                                 + listdatachild.get(                                 listdataheader.get(groupposition)).get(                                 childposition), toast.length_short)                         .show();                 return false;             }         });      }      private void preparelistdata() {         listdataheader = new arraylist<string>();         listdatachild = new hashmap<string, list<string>>();          // adding child data         listdataheader.add("cuisines");           // adding child data         list<string> cuisinelist = new arraylist<string>();         cuisinelist.add("american");         cuisinelist.add("oriental");         cuisinelist.add("chinese");         cuisinelist.add("continental");         cuisinelist.add("french");         cuisinelist.add("italian");         cuisinelist.add("middle eastern");         cuisinelist.add("mediterranean");         cuisinelist.add("mexican");         cuisinelist.add("thai");         cuisinelist.add("indian");           listdatachild.put(listdataheader.get(0), cuisinelist); // header, child data       } } 

edit: have found problem , solution well. chekc out answers section cheers!


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -