我要通過official Android tutorial for DialogFragments。稍微讓我困惑的部分是:顯示一個DialogFragment令我困惑
void showDialog() {
mStackLevel++;
// DialogFragment.show() will take care of adding the fragment
// in a transaction. We also want to remove any currently showing
// dialog, so make our own transaction and take care of that here.
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment prev = getFragmentManager().findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
DialogFragment newFragment = MyDialogFragment.newInstance(mStackLevel);
newFragment.show(ft, "dialog");
}
所以我的困惑源於一個事實,即他們正在使用findFragmentByTag("dialog")
。沒有聲明的佈局XML具有名爲dialog
的標籤。在正常的Fragmants情況下,佈局中有<fragment ../>
標籤,因此我可以使用Id或標記名檢索片段。在這裏,沒有任何。
那麼,什麼給了?這個怎麼用 ?
另外,如果我有多個DialogFragments
? findFragmentByTag("dialog");
會返回什麼?
:)
*此外,如何使用支持DialogFragment進行此項工作?* –