How To Put A Expandable Listview In Navigation Drawer?
I have created a expandable list view and i want know how to put that inside the naviagtion drawer. I have set drawerlayout in activity_main.xml but I am stuck in MainActivity. Edi
Solution 1:
example from this link
<android.support.v4.widget.DrawerLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/drawer_layout"android:layout_width="match_parent"android:layout_height="match_parent"><!-- The main content view --><FrameLayoutandroid:id="@+id/content_frame"android:layout_width="match_parent"android:layout_height="match_parent" /><!-- The navigation drawer --><ListViewandroid:id="@+id/left_drawer"android:layout_width="240dp"android:layout_height="match_parent"android:layout_gravity="start"android:choiceMode="singleChoice"android:divider="@android:color/transparent"android:dividerHeight="0dp"android:background="#111"/></android.support.v4.widget.DrawerLayout>
here list view with id left_drawer
is the drawer content and you can simple put any view here.
So simply put your expandable list view there.
Solution 2:
my solution is: write below code within NavigationDrawerFragment.java file fragment_navigation_drawer.xml is containing only ExpandableListView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
expListView = (ExpandableListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
prepareListData();
listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader,
listDataChild);
expListView.setAdapter(listAdapter);
// Listview Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// System.out.println(listDataHeader.get(groupPosition));returnfalse;
}
});
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
publicvoidonGroupExpand(int groupPosition) {
// System.out.println(listDataHeader.get(groupPosition));
}
});
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
publicvoidonGroupCollapse(int groupPosition) {
System.out.println(listDataHeader.get(groupPosition));
}
});
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
System.out.println(listDataChild.get(
listDataHeader.get(groupPosition)).get(childPosition));
mTitle = listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition);
selectItem(groupPosition);
returnfalse;
}
});
return expListView;
}
Post a Comment for "How To Put A Expandable Listview In Navigation Drawer?"