Android Dialog(2) -Custom Dialog-

In the previous article, I have taken up an example of displaying a ready-made dialog, AlertDialog. This time, I will take up creating and displaying a custom dialog.

For time setting, there are ready-made dialog, TimePickerDialog. As a simple example, we try to make a custom dialog that has a TimePicker widget and CheckBox to allow you to check it.

First, I define the layout of the dialog and save it as xml file in res/layout. Here, it is defined as follows res/layout/test_dialog.xml.

Next, in onCreateDialog method, I apply the layout to my dialog. Since this example is a custom dialog, I directly generate an instance of Dialog without using the Builder.

1.Case without DialogFragment

2.Case with DialogFragment

When you display the above dialog, you can see the following screen.


For information on how to display the dialog that you define, please refer to the article Android Dialog(1)

[Related articles]
Android Dialog(1)
Android Dialog(1) – 2 Supplement

Your email address will not be published.