Brian Fraser | AlertDialog via Fragment: Android Programming @DrBFraser | Uploaded 7 years ago | Updated March 01 2023
Create an AlertDialog using AppCompatDialogFragment. Interact with the parent activity by setting text in a TextView, and by closing it with .finish().
Steps:
- Setup MainActivity with a TextView to edit, and a button to trigger the dialog box.
- Create a layout XML file for the dialog's appearance
- Create a Java class inheriting from AppCompatDialogFragment to build the AlertDialog
- Show the AlertDialog from main using a fragment manager.
- Add a cancel button
- Call .finish() on the parent activity to close it.
Create an AlertDialog using AppCompatDialogFragment. Interact with the parent activity by setting text in a TextView, and by closing it with .finish().
Steps:
- Setup MainActivity with a TextView to edit, and a button to trigger the dialog box.
- Create a layout XML file for the dialog's appearance
- Create a Java class inheriting from AppCompatDialogFragment to build the AlertDialog
- Show the AlertDialog from main using a fragment manager.
- Add a cancel button
- Call .finish() on the parent activity to close it.