I want to implement a Drawermenu in my Android App with the Options:
For the implementations of the Drawermenu there are plenty of tutorials and all are very clear, however I cannot find anything on adding a Submenu similar to this one in my Reddit app:
With click on "My Subscriptions" the List of my Subscriptions expands.
Is this really this hard to realize? Any Idea or advice is appreciated
I have the Drawer set up like this:
Layout XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#ffeeeeee"/>
</android.support.v4.widget.DrawerLayout>
MainActivity:
package com.example.simon.drawtest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
private ListView mDrawerList;
private ArrayAdapter<String> mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
addDrawerItems();
}
private void addDrawerItems() {
String[] osArray = {"Profile", "Settings", "Info"};
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
}
}
Thanks guys!
You need to replace your ListView with an ExpandableListView. This is a good tutorial to start.