So I'm trying to add some content to my navigation drawer dynamically. In principle, it works. I can add stuff in my app, and I can make it show up in the navigation drawer. Only problem is, I have to restart the app for the new stuff in the navigation drawer to popup (because I can only get the code working in the onCreate method), which is not the desired behaviour.
This is what I've got in the onCreate method at the moment:
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
Menu menu = navigationView.getMenu();
MenuItem it1 = menu.add(R.id.group1, 1, 2, "TEST DYNAMIC");
Very basic, but it does what I want. It adds a "test" header to the menu.
What I want, is to be able to access this bit of code at will, so for example when I press a button. I haven't been able to do this myself unfortunately. It doesn't matter if it's in a method in the MainActivity, or in one of my other fragments, but it shouldn't only be run when the MainActivity is created, that's not enough. Also, I probably need a Navigation Drawer re-draw after adding something to it (I'm guessing), but I don't know how to do that either, so any help on that would be great.