我有導航抽屜,它上面有物品。但是當我點擊時,沒有任何反應。這段代碼有什麼問題?當我點擊裏面的物品時,NavigationItemSelectedListener無法觸發
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.navi_1:
Intent intent = new Intent(BaseOrderActivity.this,BaseOrderActivity.class);
intent.putExtra("dataDealerCode",dataorderCode);
startActivity(intent);
finish();
return true;
case R.id.navi_2:
Intent intent2 = new Intent(BaseOrderActivity.this,MappingProductRecycler.class);
intent2.putExtra("dataDealerCode",dataorderCode);
startActivity(intent2);
finish();
return true;
case R.id.navi_3:
Intent intent3 = new Intent(BaseOrderActivity.this,UpdateProductActivity.class);
intent3.putExtra("dataDealerCode",dataorderCode);
startActivity(intent3);
finish();
return true;
case R.id.navi_4:
return true;
}
//drawerLayout.closeDrawers();
return true;
}
});
當我把斷點NavigationItemSelected,它不會停止在斷點,所以我不能啓動我的選擇對其他活動的基礎。爲什麼?
這是我的佈局:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
<FrameLayout
android:animateLayoutChanges="true"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BaseOrderActivity"
/>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navigation"/>
<RelativeLayout
android:id="@+id/main_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BaseOrderActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tab_layout"
android:layout_y="50dp" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
什麼錯我的佈局?
嘗試把你的onNavigationItemSelected,DrawerLayout抽屜=(DrawerLayout)findViewById(R.id.drawer_layout)結束; drawer.closeDrawer(GravityCompat.START); invalidateOptionsMenu(); 返回true; – zephyr
你能告訴我們你的XML爲導航抽屜和菜單項嗎? –
@zephyr我已經把這段代碼放到了我的onNavigationSelected結尾,但它沒有任何改變。 –