我想在應用程序中使用滑動導航抽屜。但是,它似乎沒有處理OnItemClick方法。當我點擊一個項目什麼我happens.How使它發揮作用?謝謝滑動導航抽屜不處理點擊菜單項android
// MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawer_layout = (DrawerLayout)findViewById(R.id.drawerLayout);
list_view = (ListView)findViewById(R.id.drawerList);
menu_items = getResources().getStringArray(R.array.nav_drawer_items);
list_view.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, menu_items));
list_view.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, menu_items[position] + " was selected", Toast.LENGTH_LONG).show();
}
// MainActivity.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/mainContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="@+id/drawerList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/white"
android:divider="@android:color/black"
android:dividerHeight="1dp"
android:listSelector="@android:color/black"
android:choiceMode="singleChoice"
/>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:ignore="MergeRootFrame"
tools:context="com.example.MainActivity"
>
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textview1"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="center"
android:layout_marginTop="30dp"/>
<Button
android:id="@+id/Button1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="@drawable/ok_button"
android:layout_marginTop="20dp"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
正確,我不是usi在z_order中。現在它可以工作。謝謝一堆 – artist 2014-09-04 01:08:44