In my main activity, I have an action bar with NAVIGATION_MODE_TABS . The contents of each tab is a piece of the list.
I would like to make a new fragment appear when I click on a list item and the action bar mode is changed to NAVIGATION_MODE_STANDARD (so the tabs are now hidden).
I managed to get this to work with the following code:
In the listitemclick method:
ActionBar actionBar = getActivity().getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); Fragment albumListFragment = new AlbumListFragment(); albumListFragment.setArguments(bundle); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(android.R.id.content, albumListFragment); ft.addToBackStack(null); // Commit the transaction ft.commit(); Log.i("FragmentList", "Item clicked: " + id);
The problem is when I click the back button, the tabs are still missing and the previous snippet is not coming back.
I'm doing something wrong. Does this have anything to do with the backstack fragment? Do I have to go this route in another way or even cancel the feed?
- Edit -
For clarity, I call addToBackStack when I call the fragmentation function. replace, but when I click the back button, the previous fragment is not restored.
Tim malseed
source share