I am going over the official Android tutorial for DialogFragments. The part that slightly confuses me is:
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");
}
So my confusion arises from the fact that they are using findFragmentByTag("dialog"). Nowhere is a layout XML declared that has a tag named dialog in it. In case of normal Fragmants, there are <fragment ../> tags in the layout so I can retrieve fragments with Id or tagname. Here, there isn't any.
So, what gives ? How does this work ?
Also, what if I have multiple DialogFragments ? findFragmentByTag("dialog"); will return what??
:)