Search code examples
androidandroid-activitydialogfragment

DialogFragment without FragmentActivity


Is it possible to use a DialogFragment when using an Activity instead of a FragmentActivity? The show() methods needs a FragmentManager.

I want to implement a Dialog which contains just one EditText, and the tutorials on android developers says I have to use a custom layout on a dialog fragment. So I asked cause I don't feel like changing to use FragmentActivity just for 1 dialog.

SOLVED: I decided just to use FragmentActivity instead of Activity so it won't get more complicated.


Solution

  • I encountered the same problem. I know you asked this a year ago, but still to help other users. This is how I resolved the problem.

    public void show_dialog() {
        FragmentManager fm = getFragmentManager();
        DialogFragment newFragment = new DialogFragment();
        newFragment.show(fm, "abc");
    }
    

    This just requires the FragmentManager import, not the FragmentActivity.