Android – On navigation drawer item click, new list view in navigation drawer

androidlistviewnavigationnavigation-drawerslider

I am trying to get the following functionality in navigation drawer but i am not able to break it.

scenario:-

I am having a Navigation Drawer. On clicking any item in the navigation drawer I need a list view to open with multiple item in it, which could be further selected for some kind of functionality.
I am also attaching the Image which will Define my need in appropriate manner. Please have a kind reference of the Image to get What I basically and actually need.navigation drawer with multiple list

Any help would be appreciated..!

Best Answer

As i Have see your image what i understand is that, from your drawer click you want another list appear it's right side . am I correct ? If I correct then it is not possible using ExpandableListView becuase ExpandableListView will generate the item below the clicked item.

So one solution is that You can take two ListView.

First ListView inside drawer and Second one on your main content and create custom adapter for both ListView.

Now when user click drawer list item, identify which option is clicked like City, MyNews or whatever.

After identifying the click you can fill your adapter for second ListView according to which option is clickd by user. and apply that adapter to second ListView and notify it.

So when user click on another item from drawer the same thing going to happen. But the data for second ListView are going to change.

I hope you understand what I am saying and It helps you.

[update]

Ok so your xml shuold look like this.

Note: I am just writing a skeleton for this.

<!-- The main content view -->
<FrameLayout android:id="@+id/content_frame" />

<!-- The navigation drawer -->
<LinearLayout
    android:layout_gravity="start"
    android:orientation="horizontal">
    <ListView
        android:layout_weight="1"
        android:id="@+id/list1">
    </ListView>

    <ListView
        android:layout_weight="1"
        android:id="@+id/list2">
    </ListView>
</LinearLayout>

Now On Your java side. consider both listview are referenced as list1 and list2 , and you have created two adapter adapter1 and adapter2.

Make Item click for list1 and apply the logic like below ...

list1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {

        // now here you can get which option is clicked from list1.
        // using position and 
        int your_type = pos;

        adapter2.filderDataAccordingToType(your_type);
        // create the above method in your second adapter and pass your type like MyNews, City or any other.
        // and apply the logic of filtering by passing type to your method
        // your_type could be any data type i have take the integer.
        // and after filtering data you can notify your adapter.
        // so when the data of adpater gets changed your secondlistview get refreshed.
    }
});

that's it. I hope it helps you.