I have a Bottombar. When you click on an Item from there a Fragment will fill the Space who left between Bottombar and the top of the screen. When you click on an Item this Code will be run:
case R.id.navigation_search:
Fragment_search fragment_search = new Fragment_search();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment_search);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
return true;
You see I add the Fragment to the BackStack. Everything works fine, but when the User clicks the Back button from Android only the previous Fragment will load without that the Bottombar will select the Item which the Fragment has. So how to do that when a Fragment is called the appropriate Item will be selected? Is there something like onFragmentChange?? And how to select Item from Bottombar?
Thanks in advance.
If you want the back button to change the bottom bar you can intercept it and tell it which item to select.
@Override
public void onBackPressed()
{
super.onBackPressed();
// Figure out which fragment is now showing and select the item in the bottom bar.
}
You might also need to intercept the back arrow if you have an actiobar / toolbar.