Dynamique des Menus dans la fenêtre des éléments

J'ai cette Mise en page:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- The ActionBar -->
    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/flContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:menu="@menu/drawer_menu"
    app:headerLayout="@layout/nav_header"/>

Donc que, dans NavigationView nous avons l'attribut:

  app:menu="@menu/drawer_menu"

Et j'ai un XML id de menu de dossier.

Je veux faire dinamicament menus, c'est à dire, dans le code, je dois monter le 'MenuItem' objets et NavigationView.

C'est correct?
C'est la meilleure pratique?
Est-ce possible?

Note: Mon code est de travailler avec static drawer_menu, je veux l'améliorer.

Je suis en attente.

[MODIFIER]

Je le fais:

 Menu menu = nvDrawer.getMenu();
        for (KSMenuItem kmi : menus.values()) {
            if (menu.size() == 0) {
                menu.add(kmi.getId());
            }
            if (menu.getItem(kmi.getId()) == null) {
                menu.add(kmi.getId());
            }
            MenuItem mi = menu.getItem(kmi.getId());
            mi.setIcon(kmi.getIcon());
            mi.setTitle(kmi.getTittle());
        }

Mais cette erreur s'est produite:

06-27 15:26:15.538 15335-15335/? E/AndroidRuntime﹕ EXCEPTION FATALE: principal
Processus: com.exemple.sticdev30.newdrawer, PID: 15335
java.lang.RuntimeException: Impossible de démarrer l'activité ComponentInfo{com.exemple.sticdev30.newdrawer/com.exemple.sticdev30.newdrawer.MainActivity}: android.contenu.res.Ressources$NotFoundException: String resource ID #0x1

KSMenuItem est un POJO avec mon menu données. Dans kmi.id-je informé de l'incrémental entiers...

Je suis waitning

checkout ma réponse ici :stackoverflow.com/a/30706233/3544839
S'il vous plaît, voir mon edit.

OriginalL'auteur Dimmy Magalhães | 2015-06-26