'Unable to select any of the items in the menu

I have to get the toast when i click on the profile item and move to other activity when i click on the SignOut items. but nothing is happening and unable to click too.

MainActivity code: where i have all the functionalities to set up the nav and its menu items

class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener { // to make items on menu selectable
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        setUpActionBar()
        // setting up the nav_view
        nav_view.setNavigationItemSelectedListener(this)
    }

    private fun setUpActionBar() {
        setSupportActionBar(toolbar_main_activity)
        title = "Thinking"
        toolbar_main_activity.setNavigationIcon(R.drawable.ic_baseline_menu_24)
        toolbar_main_activity.setNavigationOnClickListener { toggleDrawer() }
    }

    private fun toggleDrawer() {
        if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
            drawer_layout.closeDrawer(GravityCompat.START)
        } else {
            drawer_layout.openDrawer(GravityCompat.START)
        }
    }

    override fun onBackPressed() {
        if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
            drawer_layout.closeDrawer(GravityCompat.START)
        } else {
            doubleBackToExit()
        }
    }

    override fun onNavigationItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            R.id.nav_my_profile -> {
                Toast.makeText(this, "My profile", Toast.LENGTH_LONG).show()
            }
            R.id.nav_sign_out -> {
                FirebaseAuth.getInstance().signOut()
                startActivity(Intent(this, IntroActivity::class.java))
                finish()
            }
            else -> {
                drawer_layout.closeDrawer(GravityCompat.START)
            }
        }
        return true
    }
}

Menu Code: I have used two items

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_my_profile"
            android:icon="@drawable/ic_nav_user"
            android:title="My profile" />

        <item
            android:id="@+id/nav_sign_out"
            android:icon="@drawable/ic_nav_sign_out"
            android:title="Sign out" />
    </group>

</menu>

XML Activity: I have included another activity to display upon this activity

<?xml version="1.0" encoding="utf-8"?>
<!-- Drawer Layout creation-->
<androidx.drawerlayout.widget.DrawerLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    android:theme="@style/Custom_Theme"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"/>

    <include layout="@layout/main_content" />

</androidx.drawerlayout.widget.DrawerLayout>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source