문제

Is it possible to show a FragmentDialog 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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top