Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FragmentTransaction with a DialogFragment

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

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>

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.

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

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.

Thanks

like image 352
Joey Avatar asked Apr 08 '11 14:04

Joey


1 Answers

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.

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.

like image 58
alexanderblom Avatar answered Oct 03 '22 22:10

alexanderblom