1

私は API レベル 10 の SDK 最小値で作業しています。したがって、サポート V4 ライブラリを使用して DrawerLayout を作成しています。これが私が行っていることです。

manager = MainScreenActivity.getDeviceManager();
    String[] drawerInfo = manager.getDrawerInfo();

    DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ListView mDrawerList = (ListView) findViewById(R.id.devices_left_drawer);

    // Set the adapter for the list view
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.id.devices_left_drawer, drawerInfo));
    // Set the list's click listener
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

        }
    });

XML:

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

    <FrameLayout
        android:id="@+id/devices_content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <ListView
        android:id="@+id/devices_left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>

</android.support.v4.widget.DrawerLayout>

これを開くと、「Resource$NotFoundException」という例外が発生します。奇妙なことに、DeviceManager (自分のカスタム クラス) にデバイスがないとしましょう。引き出しは正常に機能し、100% 拡張して閉じます。ただし、deviceManager がデバイスを見つけてその名前 (文字列) をリストに追加し、それを DrawerLayout に追加しようとすると、DrawerLayout アクティビティを開くとすぐにクラッシュします。(文字列をハードコーディングしてもクラッシュします) 何が問題なのですか?

4

0 に答える 0