Created
October 4, 2017 10:06
-
-
Save strombringer/86ddbb73b632d78c73c61ecf605ada27 to your computer and use it in GitHub Desktop.
Android: DialogFragment embedded or as Dialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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