我尝试使用线性布局将 edittext 字段添加到导航抽屉,如以下代码所示。
<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"
android:background="@android:color/white" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<LinearLayout
android:id="@+id/left_drawer"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical" >
<EditText
android:id="@+id/EditText01"
android:layout_width="240dp"
android:layout_height="match_parent"
android:hint="Search" >
</EditText>
<ListView
android:id="@+id/left_drawer_child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
但是当我试图填充列表视图时,它给了我一个空指针异常。这是我使用的代码
DrawerLayout mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
LinearLayout mDrawerLinear = (LinearLayout) findViewById(R.id.left_drawer);
ListView mDrawerListChild = (ListView) findViewById(R.id.left_drawer_child);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.drawer_listview_item, drawerListViewItems);
mDrawer.closeDrawer(mDrawerLinear);
错误:
Caused by: java.lang.NullPointerException
我在这里做错了什么?
谢谢!