开发者

Showing DialogFragment from an ActionBar.TabListener

开发者 https://www.devze.com 2023-03-01 09:48 出处:网络
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 met

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号