Adding Expandablelistview to Navigationview

Android Navigation Drawer ExpandableListView

If you want to achieve above behavior to your NavigationDrawer you can follow below steps:

1) You have to add Expandable listview to your NavigationView.

2) Create Header View

3) Create Child View.

4) Extend BaseExpandableListAdapter

5) Set Adapter in MainActivity

There are few solutions available. You can follow this tutorial or this. For basic knowledge about creating Navigation drawer, you can go here. I got helped by these tutorials and they are very easy to apply.

Hope this helps.

How to integrate expandable list view inside navigation drawer?

You can do it by adding ExpandableListView in NavigationDrawer like below:

You can create it using custom ListView.

See the code below activity_navigation_view.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">

<ExpandableListView
android:id="@+id/navigationmenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="192dp"
android:background="@android:color/white">
</ExpandableListView>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

And Simply create adapter for it and use it like a normal ExpandableListView.

The expandableListview is not scrolling with other menu items in navigationview

After a huge try, I have come to realize that expandablelistview inside a navigationview will work only if u put all the contents of the navigationview inside in the expandable listview because if u choose to use both menu and expandable listview inside the navigationview to populate the items then most probably the expamdablelistview will not be connected to header of the navigationview and it will not scroll with other items of navigationview and it will never sync to complete the format. so just add all the menuitems inside expandablelistview and make others childless to clone them like normal menu items

how to create an expandable listView inside navigation drawer?

You can create an ExpandableListView and use it as your NavigationView. An example of xml result:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".MainActivity">

<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<!-- This DrawerLayout has two children at the root -->
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="@+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->

<ExpandableListView
android:id="@+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="start"/>

</android.support.v4.widget.DrawerLayout>

You can find an example of using an ExpandableListView here



Related Topics



Leave a reply



Submit