我试图使用线性布局将edittext字段添加到导航抽屉,如下面的代码所示。Android导航抽屉阵列适配器
<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
我在做什么错在这里?
谢谢!
你可以发布更多的堆栈跟踪或者说你得到NullPointerException的地方......可能会帮助你理解这个问题。这个'drawerListViewItems'是什么,你在哪里初始化它? – Mikel
看到这个http://hmkcode.com/android-creating-a-navigation-drawer/ –