'Not able to select options from side menu and navigate to different screens
I have made one dashboard screen in that screen I added side bar navigation so for this I made sidemenu.xml and headerfile.xml and I added these both sidemenu.xml and headerfile.xml to dashboard.xml now I want when I click on any options from side bar navigation it should navigate to their respective screens.
sidemenu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
//menu one
<group android:checkableBehavior="single">
<item
android:id="@+id/profile_menu"
android:icon="@drawable/profile"
android:title="Profile" />
<item
android:id="@+id/home_menu"
android:icon="@drawable/ic_outline_home_24"
android:title="Home" />
<item
android:id="@+id/dashboard_menu"
android:icon="@drawable/ic_outline_dashboard_24"
android:title="Dashboard" />
<item
android:id="@+id/services_icon"
android:icon="@drawable/ic_outline_miscellaneous_services_24"
android:title="Services" />
</group>
// menu two
<group
android:checkableBehavior="single">
<item android:title="Authentication">
<menu>
<item
android:id="@+id/login_menu"
android:icon="@drawable/ic_baseline_login_24"
android:title="Login" />
<item
android:id="@+id/logout_menu"
android:icon="@drawable/ic_outline_logout_24"
android:title="Logout" />
</menu>
</item>
</group>
//menu three
<item android:title="Sharing">
<menu>
<item
android:id="@+id/share_menu"
android:icon="@drawable/ic_baseline_share_24"
android:title="Share" />
<item
android:id="@+id/refer_menu"
android:icon="@drawable/ic_baseline_send_24"
android:title="Refer" />
</menu>
</item>
</menu>
activity_dashboard.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".dashboard"
tools:openDrawer="start">
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigationview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/headerfile"
app:menu="@menu/sidemenu" />
Solution 1:[1]
First, Make sure that you want to navigate different fragment or layout. If you want to navigate different fragment then add all IDs of sidemenu.xml in mobile_navigation.xml (make sidemenu.xml and mobile_navigation.xml id same) and if you know how to? then please add code of your navigation>mobile_navigation.xml and also code of MainActivity. Because half code cannot solve any problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
