【发布时间】:2014-03-07 01:51:09
【问题描述】:
试图将复杂的 DialogFragment 重用为 Activity 布局中的 Fragment。我不想重写整个 DialogFragment 类,因为它非常复杂。在一个地方,设计师只希望这种布局不是作为弹出窗口而是在页面中。有没有办法绕过 DialogFragment 抛出这个(来自 DialogFragment.java):
if (view != null) {
if (view.getParent() != null) {
throw new IllegalStateException("DialogFragment can not be attached to a container view");
}
mDialog.setContentView(view);
}
我什至在 OnCreateDialog() 重写方法中取消了 Dialog 的创建,并添加了 onCreateView() 重写方法。但仍然视图不为空并抛出 IllegalStateException。我在活动布局中嵌入了片段
<fragment
android:id="@+id/fragment_mine"
android:name="com.test.MyDialogFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
所以问题是,有没有办法在 Activity 的布局中重新使用 DialogFragment 作为 Fragment?
【问题讨论】:
标签: android android-fragments android-dialogfragment