Master Detail流程的基本模板使用boolean mTwoPane
值来确定是否有两个窗格或一个窗格。但是,它是在ListFragment
呈现之后设置的。我想为小型设备创建一个ListView
,这些设备会在不同的活动中显示DetailFragment
,在设备上显示不同的ListView
,这会将DetailFragment
并排呈现给ListFragment
。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_list);
if (findViewById(R.id.item_detail_container) != null) {
// The detail container view will be present only in the
// large-screen layouts (res/values-large and
// res/values-sw600dp). If this view is present, then the
// activity should be in two-pane mode.
mTwoPane = true;
// rest of code
}
我在确定setContentView(R.layout.activity_item_list)
后尝试使用mTwoPane
,但mTwoPane
始终保持为假。我也尝试过使用setContentView(R.layout.activity_item_list)
两次,在if块之前和之后,但应用程序崩溃了。
非常感谢任何帮助。
答案 0 :(得分:0)
在您的布局中,只有在FrameLayout
向Fragment
添加if block
后才能使用Fragment
(而非FrameLayout
)。
删除xml中的“fragment
”标记,以便完全控制Fragment
管理。