Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationView with multiple group hide & show group based on Condition

I have NavigationView with multiple Groups which is based on some condition I need to hide & show the group. How I can achieve this.

My Sample NavigationView menu

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

 <group android:checkableBehavior="single"
        android:id="@+id/grp_employee"
        >

        <item
            android:id="@+id/help"
            android:checked="false"
            android:icon="@drawable/ic_help"
            android:title="@string/app_name" />

.......
</group>

<group android:checkableBehavior="single"
        android:id="@+id/grp_admin"
        >

        <item
            android:id="@+id/admin_help"
            android:checked="false"
            android:icon="@drawable/ic_help"
            android:title="@string/app_name" />

.......
</group>

<group> ... </group>

</menu>

This is the my NavigationView file. I just want to show only one group view at a time hide all others group.

like image 825
Maheshwar Ligade Avatar asked May 13 '16 02:05

Maheshwar Ligade


1 Answers

Well, you can use Menu.setGroupVisible (int group, boolean visible) to hide or show menu group.

navigationView.getMenu().setGroupVisible(R.id.group_id,false);//to hide
navigationView.getMenu().setGroupVisible(R.id.group_id,true);//to show
like image 139
Bharatesh Avatar answered Oct 24 '22 16:10

Bharatesh