Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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..!

like image 296
Pravinsingh Waghela Avatar asked Jun 28 '15 19:06

Pravinsingh Waghela


People also ask

What is a navigation drawer?

The navigation drawer is a UI panel that shows your app's main navigation menu. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen.

What is navigation drawer activity in Android?

Android Navigation Drawer is a sliding left menu that is used to display the important links in the application. Navigation drawer makes it easy to navigate to and fro between those links. It's not visible by default and it needs to opened either by sliding from left or clicking its icon in the ActionBar.


2 Answers

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.

like image 76
Moinkhan Avatar answered Oct 19 '22 23:10

Moinkhan


You can use the Android Developers tutorial on creating a navigation drawer, but instead of using ListView, you go for an ExpandableListView.

For example, in that tutorial, you can see that in the first block of code they are using a ListView. Instead of that, change it to something like this:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ExpandableListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>

How to implement a ExpandableListView adapter is well explained in this tutorial available at Android Hive. I'm not pasting their code here because it's a long tutorial. Comment bellow if you have any questions.

like image 27
VulfCompressor Avatar answered Oct 19 '22 23:10

VulfCompressor