Created
May 30, 2022 04:04
-
-
Save yasukotelin/39c0387cf6239996a4863c497a603525 to your computer and use it in GitHub Desktop.
DialogFragmentの重複表示を避ける拡張関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 同じtagのDialogFragmentの存在チェックを実施し、ない場合に限り表示する | |
* | |
* @tag タグ名でチェックするため、一意の値を指定してください | |
*/ | |
fun DialogFragment.showIfNotAdded(fragmentManager: FragmentManager, tag: String) { | |
if ((fragmentManager.findFragmentByTag(tag) as? DialogFragment)?.dialog == null) { | |
showNow(fragmentManager, tag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
isAdded
やisShow
では、まだ表示しきっていない時にfalseを返してくるため重複表示を避けられない。findFragmentTagを使うことで確実に重複表示を回避する。