Modify the activity_main_drawer.xml from an external server xml

4

I have this file activity_main_drawer.xml inside the folder res/menu/

<?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_inicio"
            android:icon="@mipmap/ic_home"
            android:title="@string/inicio" />
    </group>
</menu>

What I try to do is modify it, based on a xml I get from an external server. Or instead of modifying it, use the xml external%, instead of this for the side menu of android

EDIT

The server's xml is like this:

<?xml version="1.0" encoding="utf-8"?>
<zonas>
    <zona>
        <idZona>1</idZona>
        <nombre idZona="1">Home</nombre>
    </zona>
    <zona>
        <idZona>2</idZona>
        <nombre idZona="2">Pantalla 1</nombre>
    </zona>
    <zona>
        <idZona>3</idZona>
        <nombre idZona="3">Pantalla 2</nombre>
    </zona>
    <zona>
        <idZona>4</idZona>
        <nombre idZona="4">Pantalla 3</nombre>
    </zona>
</zonas>

And I read it by Parser SAX

    
asked by Joacer 29.05.2017 в 14:00
source

1 answer

2

If I'm wrong, you can change the Navigation Drawer elements in the OnCreate() method of your Activity . In the beginning I can think of several options:

- Option 1 : change the menu to another one that exists in the resources. Example:

 navigationView.getMenu().clear(); //Borrar los elementos anteriores.
 navigationView.inflateMenu(R.menu.new_navigation_drawer_items);

- Option 2 : change the menu by manually adding the menu items using the functions of the menu add () and addSubMenu () . Example:

 Menu menu = navigationView.getMenu();
 for (int i = 1; i <= 3; i++) {
     menu.add("Menu "+ i);
 }

 SubMenu subMenu = menu.addSubMenu("SubMenu");
 for (int i = 1; i <= 2; i++) {
     subMenu.add("SubMenu " + i);
 }
    
answered by 29.05.2017 / 15:39
source