Dialog

A dialogue is a small window which prompts the user to make a decision or to enter additional data.

Often in your application, you can use Warning Dialog if you wanted to ask the user to mdecision between yes or no in response to any specific action taken by the user, by staying isame operation and without changing the screen.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
val alertDialogBuilder = AlertDialog.Builder(context)
alertDialogBuilder.setPositiveButton("OK", 
    object: DialogInterface.OnClickListener {
       override fun onClick(dialog: DialogInterface?, which: Int) {
           Toast.makeText(context, "OK button clicked", 
           Toast.LENGTH_SHORT).show()}})  
alertDialogBuilder.setNegativeButton("CANCEL", 
    object: DialogInterface.OnClickListener {
          override fun onClick(dialog: DialogInterface?, which: Int) {
             Toast.makeText(context, "CANCEL button clicked", 
             Toast.LENGTH_SHORT).show()}})                         

You can generate an warning dialogue after creating and setting the dialogue builder by cathe builder class’s generate method. Its syntax is:

1
2
val alertDialog = alertDialogBuilder.create()
alertDialog.show()