我有导航抽屉,它上面有物品。但是当我点击时,没有任何反应。这段代码有什么问题?当我点击里面的物品时,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结尾,但它没有任何改变。 –