android - Navigation Drawer with expandable list inside doesn't work -


after several researching , resembling of codes, expandable list inside navigation drawer doesnt work. there of guys have tried doing this.i appreciate if can me this. im striving 3 days.please me.

am miss on code?

heres code:

mainactivity

public class mainactivity extends activity {  expandablelistadapter listadapter; expandablelistview explistview;  public drawerlayout drawer; private linearlayout linear; button btn;  hashmap<string, list<string>> listdatachild; list<string> listdataheader;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);       btn = (button)findviewbyid(r.id.button1);     linear = (linearlayout)findviewbyid(r.id.linear);     explistview = (expandablelistview) findviewbyid(r.id.lvexp);     drawer = (drawerlayout)findviewbyid(r.id.drawer_layout);      preparelistdata();      btn.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view arg0) {             // todo auto-generated method stub         if(!drawer.isdraweropen(explistview))         {             drawer.opendrawer(explistview);         }         else         {             drawer.closedrawer(explistview);         }          }     });      // listview       // preparing list data       listadapter = new expandablelistadapter(this, listdataheader, listdatachild);      // setting list adapter     explistview.setadapter(listadapter);      // listview group click listener     explistview.setongroupclicklistener(new ongroupclicklistener() {          @override         public boolean ongroupclick(expandablelistview parent, view v,                 int groupposition, long id) {             // toast.maketext(getapplicationcontext(),             // "group clicked " + listdataheader.get(groupposition),             // toast.length_short).show();             return false;         }     });      // listview group expanded listener     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;         }     }); }  /*  * preparing list data  */ private void preparelistdata() {     listdataheader = new arraylist<string>();     listdatachild = new hashmap<string, list<string>>();      // adding child data     listdataheader.add("top 250");     listdataheader.add("now showing");     listdataheader.add("coming soon..");      // adding child data     list<string> top250 = new arraylist<string>();     top250.add("the shawshank redemption");     top250.add("the godfather");     top250.add("the godfather: part ii");     top250.add("pulp fiction");     top250.add("the good, bad , ugly");     top250.add("the dark knight");     top250.add("12 angry men");      list<string> nowshowing = new arraylist<string>();     nowshowing.add("the conjuring");     nowshowing.add("despicable me 2");     nowshowing.add("turbo");     nowshowing.add("grown ups 2");     nowshowing.add("red 2");     nowshowing.add("the wolverine");      list<string> comingsoon = new arraylist<string>();     comingsoon.add("2 guns");     comingsoon.add("the smurfs 2");     comingsoon.add("the spectacular now");     comingsoon.add("the canyons");     comingsoon.add("europa report");      listdatachild.put(listdataheader.get(0), top250); // header, child data     listdatachild.put(listdataheader.get(1), nowshowing);     listdatachild.put(listdataheader.get(2), comingsoon); } } 

heres activity_main layout

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#f4f4f4" >  <linearlayout     android:id="@+id/linear"     android:layout_width="match_parent"     android:layout_height="50dp"     android:background="#000000"     android:orientation="vertical" >      <linearlayout         android:layout_width="wrap_content"         android:layout_height="match_parent" >          <button             android:id="@+id/button1"             android:layout_width="47dp"             android:layout_height="45dp"             android:background="@drawable/arrow_right" />     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:gravity="center_vertical" >          <textview             android:id="@+id/textview1"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="drawer"             android:textappearance="?android:attr/textappearancelarge" />     </linearlayout>      <android.support.v4.widget.drawerlayout          android:id="@+id/drawer_layout"         android:layout_width="match_parent"         android:layout_height="match_parent">         <!-- main content view -->         <framelayout             android:id="@+id/content_frame"             android:layout_width="match_parent"             android:layout_height="match_parent" />         <!-- navigation drawer -->           <expandablelistview             android:id="@+id/lvexp"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_gravity="start"             android:cachecolorhint="#00000000" >         </expandablelistview>     </android.support.v4.widget.drawerlayout>   </linearlayout>  </linearlayout> 

my baseadapter:

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; //private layoutinflater vi;  public expandablelistadapter(context context, list<string> listdataheader,         hashmap<string, list<string>> listchilddata) {     this._context = context;     this._listdataheader = listdataheader;     this._listdatachild = listchilddata;     //vi = (layoutinflater)context.getsystemservice(context.layout_inflater_service); }   @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.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.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; }  } 

i think need add xml this

  <?xml version="1.0" encoding="utf-8"?>  <android.support.v4.widget.drawerlayout     xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:orientation="vertical"      android:background="#f4f4f4" >  <linearlayout android:id="@+id/linear" android:layout_width="match_parent" android:layout_height="50dp" android:background="#000000" android:orientation="vertical" >  <linearlayout     android:layout_width="wrap_content"     android:layout_height="match_parent" >      <button         android:id="@+id/button1"         android:layout_width="47dp"         android:layout_height="45dp"         android:background="@drawable/arrow_right" /> </linearlayout>  <linearlayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="center_vertical" >      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="drawer"         android:textappearance="?android:attr/textappearancelarge" /> </linearlayout>  </linearlayout>       <expandablelistview         android:id="@+id/lvexp"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_gravity="left"         android:cachecolorhint="#00000000" >     </expandablelistview> </android.support.v4.widget.drawerlayout> 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -