Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a Menu of a NavigationView programmatically?

Tags:

Hello I'm wondering how can I change a Menu ID from a NavigationView, in this case it is triggered when the user clicks on a RadioButton. I have that part already but I just need to know how to change the Menu, so in the menu it will display different options when RadioButton is clicked.

private var radioAdm:RadioButton? = null
private var radioAtle:RadioButton? = null
private var atletanav:BottomNavigationView? = null
private var menuopt = "@menu/admin_menu"

override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
     // Here is where I need to put that code
    }

I've tried this already but no success:

atleta_navbar.set(menu){menu=menuopt}
atleta_navbar.setTag(menuopt)

So in the NavigationView it will go from this:

enter image description here

To this:

enter image description here

like image 988
Angel R Avatar asked Oct 17 '18 21:10

Angel R


1 Answers

In java you could try this to re-inflate NavigationView at runtime.

navigationView.getMenu().clear(); //clear old inflated items.
navigationView.inflateMenu(R.menu.new_navigation_drawer_items);

I don't know kotlin,but the thought is same.

like image 143
navylover Avatar answered Nov 15 '22 04:11

navylover