Skip to content

Instantly share code, notes, and snippets.

@strombringer
Created October 4, 2017 10:06
Show Gist options
  • Save strombringer/86ddbb73b632d78c73c61ecf605ada27 to your computer and use it in GitHub Desktop.
Save strombringer/86ddbb73b632d78c73c61ecf605ada27 to your computer and use it in GitHub Desktop.
Android: DialogFragment embedded or as Dialog
public class CustomDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (isInLayout())
return super.onCreateDialog(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setView(R.layout.my_custom_layout)
.setTitle(R.string.my_title)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO implement
}
});
return builder.create();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (!isInLayout())
return super.onCreateView(inflater, container, savedInstanceState);
View v = inflater.inflate(R.layout.my_custom_layout, container);
return v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment