I created a navigation drawer project in android studio and created the separate fragments for my each item in the list view in drawer. However, now the items in the list are not static ones. I have a map in which i have some values based on which i have to choose whether to show a particular item or not.
I tried to change the call to setAdapter
method based on values in map. However, it breaks the code when clicked on a particular item because in my fragments i do setOnAttached
with a certain position which is hard coded such as 0,1,2
.. My question is how can I change all of this to show the corresponding fragment when any item in drawer is clicked.
Is it possible to know that this fragment should be attached to the dynamically calculated position based on the list view that I get at run time ?
public void onAttach(Activity activity) {
((MyActivity)activity).onSectionAttached(4);
}
Thanks