Using ActionBar Up Navigation in master/detail fragments

后端 未结 4 1352
生来不讨喜
生来不讨喜 2020-12-30 03:07

I have an app with master/detail layout (1 activity, 1 ListView fragment and 1 detail fragment). When the user clicks an item in the ListView, a fragment transaction instan

4条回答
  •  孤独总比滥情好
    2020-12-30 04:08

    don't: break and then return super.onOptionsItemSelected(item), rather just: return true;

    UPDATE:

    So you're saying the Activity is "restarted" based on what you see happen with Views, but can you confirm what may or may not happen to the Activity (and Fragments for that matter) by using logging in the various lifecycle methods? That way you can be sure of what the current (erroneous) behaviour is before moving forward with diagnosis.

    UPDATE:

    OK, good to be sure about behaviour :) Now regarding your question "What is the correct way to implement "up navigation" for a master/detail layout (1 activity/2fragments)? ": The typical way is that the 2 Fragments got added within a single FragmentTransaction and you simply popBackStack to remove them and go back to whatever previous state was. I think you're doubling up by manually removing a Fragment within a FragmentTransaction and then popping backstack. Try just popBackStack. Oh and just to be sure and consistent, since you're using ActionBarSherlock and support.v4 are you using a FragmentActivity (rather than an Activity) and SherlockFragment?

提交回复
热议问题