Android DialogFragment is empty

I had a problem creating dialogue. It appears, but its empty inside, only an empty field 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 the action creating the object and calling the show method:

 SomeDialog obj = new SomeDialog(); obj.show(getFragmentManager(), "randomtag"); 
+7
source share
2 answers
 return super.onCreateDialog(savedInstanceState); 

You are returning the parent method. You must return yours. Change to:

  return builder.create(); 
+6
source

In my case, the problem was

 public static DialogFragment newInstance(int param) { Bundle args = new Bundle(); args.putInt(EXTRA_PARAM, param); DialogFragment fragment = new DialogFragment(); // Here is an error. fragment.setArguments(args); return fragment; } 

Invalid string should be replaced with

 DialogFragment fragment = new YourDialogFragment(); // Or YourDialogFragment fragment = new YourDialogFragment(); 
0
source

All Articles