I am trying to create an activity with a navigation drawer.
At first it had this onNavigationDrawerItemSelected
method and it worked fine:
@Override
public void onNavigationDrawerItemSelected(final int position)
{
Fragment f = null;
FragmentManager fragmentManager = getSupportFragmentManager();
if (position == MainFragments.SOME_FRAGMENT.ordinal())
{
f = new SomeFragment();
TabsFragmentUtils.replaceFragmentInContainer(fragmentManager, f, true);
}
}
The above index of MainFragments.SOME_FRAGMENT is 1 so the code never tried to create the fragment on startup.
After that I changed the method to this:
@Override
public void onNavigationDrawerItemSelected(final int position)
{
Fragment f = null;
FragmentManager fragmentManager = getSupportFragmentManager();
if (position == MainFragments.MAIN_FRAGMENT.ordinal())
{
f = new MainFragment();
} else if (position == MainFragments.SOME_FRAGMENT.ordinal())
{
f = new SomeFragment();
}
TabsFragmentUtils.replaceFragmentInContainer(fragmentManager, f, true);
}
Now the MainFragments.MAIN_FRAGMENT is of index 0 and I see this code is trying to run and replace the container and then I get an exception: Error inflating class fragment
(probably the navigation drawer) caused by Recursive entry to executePendingTransaction
.
After debugging I realized the code doesn't go through the MainFragemnt
onCreateView
method which is initializing the fragments tabs.
What can be done about it?