我基于本教程实现了我的布局:http://android-developers.blogspot.hu/2011/02/android-30-fragments-api.html
不同之处是:
我的问题是,如果我已从左侧选择了某些内容然后将手机旋转为肖像,则最后一个选项菜单仍然存在且可见.
我认为问题来自最后一个活动的"细节"片段在方向改变后重新创建.为了测试它我创建了这两个方法:
@Override
public void onStart() {
super.onStart();
setHasOptionsMenu(true);
}
@Override
public void onStop() {
super.onStop();
setHasOptionsMenu(false);
}
Run Code Online (Sandbox Code Playgroud)
而且我正在显示正确的片段:
case R.id.prefs_medicines:
if (mDualPane) {
// Check what fragment is shown, replace if needed.
View prefsFrame = getActivity().findViewById(R.id.preferences);
if (prefsFrame != null) {
// Make new fragment to show this selection.
MedicineListF prefF = new MedicineListF();
// Execute a transaction, replacing any existing
// fragment with this one inside the frame.
FragmentTransaction ft = …Run Code Online (Sandbox Code Playgroud)