ragmentTransaction与DialogFragmen

ragmentTransaction与DialogFragmen

本文介绍了将FragmentTransaction与DialogFragment一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我创建了一个DialogFragment,它通过此技术

So I've created a DialogFragment that is shown as a dialog via this technique

现在,它已启动,并且在此弹出窗口中与用户交互时,我想在此对话框的另一个片段中滑动.我正在尝试通过FragmentTransaction.add()来执行此操作,在此我给它提供此布局中容器之一的ID.此时,我得到:

Now that it's launched and upon a user interaction within this popup I want to slide in another fragment to this dialog. I'm trying to do this via FragmentTransaction.add() where I give it the id of one of the containers in this layout. At this point I get:

java.lang.IllegalArgumentException: No view found for id 0x7f09013f for fragment <fragmentClassThatIWasPushingIn>

作为一个快速测试,我尝试将其推入容器ID中,而不是在对话框中,而是在主要支持活动中,并且效果很好.

As a quick test, I tried to push it onto a container id not in the dialog but within the main backing activity and that worked just fine.

关于DialogFragments及其容器ID是否存在不允许FragmentTransactions的内容?

Is there something about DialogFragments and its container ids that does not allow for FragmentTransactions?

作为权宜之计,我告诉我的交易隐藏当前的DialogFragment并显示此新片段,但是动画/显示有些刺耳,所以我真的很想解决此问题.

As a stopgap I've told my transaction to hide the current DialogFragment and show this new fragment, but the animation/display is a little jarring so I'd really like to sort this issue out.

谢谢

推荐答案

DialogFragment 显示为 Dialog 时,它实际上不是真正的 Fragment 在容器视图中.它是一个无容器的 Fragment ,基本上是 Dialog 的包装.

When a DialogFragment is shown as a Dialog it is not actually a real Fragment in a container view. It is a container-less Fragment which is basically a wrapper of a Dialog.

所以不,您不能在 FragmentDialog 内显示 Fragment .如果您确实想执行此操作,我认为最好的方法是创建一个样式为 Dialog 的新 Activity ,然后您也可以添加 Fragments

So no, you can not show a Fragment inside a FragmentDialog. If you really want to do this I think the best way would to create a new Activity styled as a Dialog which you can then add Fragments too.

这篇关于将FragmentTransaction与DialogFragment一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 03:00