Reputation: 1191
I'm using setDisplayHomeAsUpEnabled with a set of fragments, i.e. an activity with A, B, C, D fragments. Upon pressing setDisplayHomeAsUpEnabled, it directs to a fragment X.... I really have not idea why this is happening, as I thought I have declare the following in OnCreate() of the activity
ActionBar bar = getActionBar();
bar.setDisplayHomeAsUpEnabled(true);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
FragA fragment = new FragA();
fragmentTransaction.add(R.id.frag_container, fragment);
fragmentTransaction.commit();
everything else works fine, except the setDisplayHomeAsUpEnabled button... which always directs to fragment X(the settings page actually, i thought it would be directing to frag A!!)
Does anybody have a clue? Big thanks!!
Upvotes: 1
Views: 982
Reputation: 1904
you can override the behaviour of setDisplayHomeAsUpEnabled
. if you want to redirect to the screen where you want to just override the behaviour by following this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// do your stuff
break;
}
}
Upvotes: 2