Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 633
Christopher Francisco Avatar asked Jun 24 '13 23:06

Christopher Francisco


2 Answers

Very very simple, just use getSupportFragmentManager()

DialogConfirmRequest dialogConfirmRequest = new DialogConfirmRequest("Sem conexão com a internet");
dialogConfirmRequest.setCancelable(true);
dialogConfirmRequest.show(getSupportFragmentManager() ,"meudialog");
like image 198
Stênio Barroso de Moraes Avatar answered Sep 20 '22 17:09

Stênio Barroso de Moraes


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.

like image 41
shadyinside Avatar answered Sep 20 '22 17:09

shadyinside