菜单(抽屉)内的 expandableListView

expandableListView inside menu (drawer)

我想在生成列表视图后在边栏菜单中插入 expandableListView 我试图将它插入到 expandableListView 实例中,但它说 nullpointer here are some parts of the code

Activity_main_drawer 文件结束

<ExpandableListView
    android:id="@+id/expandablelisto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>

主要activity

ListView modeList = new ListView(this);
    String[] stringArray = new String[] { "Bright Mode", "Normal Mode" };
    ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, stringArray);
    modeList.setAdapter(modeAdapter);
    //here the problem
    ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.expandablelisto);
    expandableListView.addView(modeList);
    //end

错误

java.lang.NullPointerException

您必须使用 SimpleExpandableListAdapter 作为 ExpandableListView 例如:

   SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
                this,
                groupData,
                android.R.layout.simple_expandable_list_item_1,
                groupFrom,
                groupTo,
                childData,
                android.R.layout.simple_list_item_1,
                childFrom,
                childTo);

           ExpandableListView  expandableListView = (ExpandableListView) findViewById(R.id.expandablelisto);
            expandableListView.setAdapter(adapter);