How to have two navigation drawer and show them according to some parameter

2

Hi, I am doing a project in android studio and I have two navigation drawer, what I want to do is that when I start as a client I show the first navigation and if I start session as an employee that shows me the other navigation. I have investigated and the only thing I could do is to show one on the left and the other on the right. I do not know how to make it show only one depending on whether you are a client or if you are an employee.

[

    
asked by Jean Pierre Acosta Tomaylla 26.10.2018 в 02:52
source

1 answer

0

That is done with a if/else .

First in your xml just leave a widget.NavigationView with id / nav_view and from there delete app: menu ...

In java you will select the drawer menu:

 String vista="";             // obtienes el string para cliente/empleado
 navigationView = (NavigationView) findViewById(R.id.nav_view);   // la vista del menu drawer
 if("cliente".equals(vista)){
   //navigationView.getMenu().clear();      //elimina anterior menu drawer
   navigationView.inflateMenu(R.menu.activity_main_drawer); //carga el menu drawer
 }else                                  // en caso de "empleado"
   //navigationView.getMenu().clear(); 
   navigationView.inflateMenu(R.menu.activity_secondary_drawer); 
 }
 navigationView.setNavigationItemSelectedListener(this);

You declare the navigation view and the String view at the beginning of the class, before onCreate:

 NavigationView navigationView;
 String vista="";
    
answered by 27.10.2018 / 02:05
source