如何在导航抽屉中创建下拉列表(在Android中)?

All*_*OOP 7 android expandablelistview android-fragments navigation-drawer

我希望能够创建一个导航抽屉,其中包含一些可扩展,可选择的项目和一些不可扩展的项目.StackOverflow对类似于我的问题的共识指向了解决方案ExpandableListView(这可能甚至不适用于我的想法).在大多数情况下,人们要求的是一种方式来分隔导航抽屉中的项目,就像GMail应用程序使用标签,而不是我想要做的...

......这基本上是在这里概述的 在此输入图像描述

并且在这里(虽然全部,但有些是下拉菜单) .而不是像这样的回答.

All*_*OOP 3

在 DrawerLayout 中使用 ExpandableListView,如下所示:

<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_layout2"
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">

    <TextView
        android:id="@+id/tv_commentary_behind_nav"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|top"
        android:text="Frame text" />
</FrameLayout>
<!-- The navigation drawer -->
    <ExpandableListView
        android:id="@+id/left_drawer2"
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/white"
        android:choiceMode="multipleChoice"
        android:dividerHeight="0dp"
        />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

然后在代码中初始化,如下所示:

    private DrawerLayout drawer;
    private ExpandableListView drawerList;
    private CheckBox checkBox;
    private ActionBarDrawerToggle actionBarDrawerToggle;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.drawer_layout);
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout2);
        drawerList = (ExpandableListView) findViewById(R.id.left_drawer2);
        drawerList.setAdapter(new NewAdapter(this, groupItem, childItem));
    }
Run Code Online (Sandbox Code Playgroud)