Showing DialogFragment from an ActionBar.TabListener
Is it possible to show a Fragm开发者_JAVA百科entDialog
when a tab is selected in the ActionBar
?
The onTabSelected()
method happens inside a transaction that is commited after the execution of the method finishes. However, the show()
method in DialogFragment
does also happen in a transaction automatically, so if you try to show the dialog when the tab is selected you get a RuntimeException
because the transaction gets commited twice.
Any hints will be appreciated.
Just ignore the supplied FragmentTransaction
.
For example, you need to do this if you are using the Android Compatibility Library (ACL), because the FragmentTransaction
you get from the action bar is an Android 3.0 FragmentTransaction
, not an ACL FragmentTransaction
. So, you ignore the passed-in one and use your own.
Similarly, I would expect that you can ignore the FragmentTransaction
and display a DialogFragment
yourself without problems.
Whether the UX will make any sense is another problem. When the user accepts the dialog the tab shows... nothing?
精彩评论