V. Govorov V. Govorov - 1 year ago 51
Android Question

Android - Find id of item in SubMenu

I use Navigation activities for moving from one Activity to another. And I want to add submenu to menu of NavigationView< but can't find way to find id og item in submenu.

<item android:title="Communicate">
<item android:id="@+id/about_us" android:icon="@android:drawable/ic_menu_share"
android:title="About us" />


public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

switch (id) {
case R.id.nav_order: {
case R.id.nav_search: {

return true;

I want to add:
case R.id.about_us
But Android Studio can't find this id.
How can i make it and what i do wrong?

Answer Source

Your code worked fine for. There is one thing missing in your menu.that is:

<menu xmlns:android="http://schemas.android.com/apk/res/android"/> <!--the xmlns is missing -->