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.
Any help would be appreciated..!
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With