Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android DialogFragment is blank

I have a problem with creating a dialog. It does appear, but its empty inside, just a blank box is shown.

Dialog class:

public class SomeDialog extends DialogFragment{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();

    builder.setView(inflater.inflate(R.layout.somelayout, null));

    return super.onCreateDialog(savedInstanceState);
}
}

In an activity, creating an object and calling show method:

SomeDialog obj = new SomeDialog();
obj.show(getFragmentManager(), "randomtag");
like image 563
user1903985 Avatar asked Jan 17 '13 15:01

user1903985


People also ask

Is DialogFragment deprecated?

This method is deprecated. androidx.

What is DialogFragment?

DialogFragment is a utility class of android development that is used to show a Dialog window, Floating on top of an activity window in an android application.


1 Answers

return super.onCreateDialog(savedInstanceState);

You are returning the parent method. You should return your own . Change to :

 return builder.create();
like image 148
wtsang02 Avatar answered Sep 23 '22 18:09

wtsang02