Android Kotlin - Как мне установить значение по умолчанию для DialogInterface.OnClickListener в качестве параметра функции? - PullRequest
0 голосов
/ 09 мая 2020

Это объявление моей функции:

fun MyDialog(ctx: Context, msg: String, yestext: String = "", OnYes: DialogInterface.OnClickListener): AlertDialog

Как мне установить значение по умолчанию для «OnYes: DialogInterface.OnClickListener»?

Я пробовал OnYes: DialogInterface.OnClickListener = null но это не работает.

Ответы [ 2 ]

1 голос
/ 09 мая 2020

Ответ предоставлен @ mangkool

On Да: DialogInterface.OnClickListener? = ноль

0 голосов
/ 09 мая 2020
val builder = AlertDialog.Builder(this@MainActivity)

            // Set the alert dialog title
            builder.setTitle("App background color")

            // Display a message on alert dialog
            builder.setMessage("Are you want to set the app background color to RED?")

            // Set a positive button and its click listener on alert dialog
            builder.setPositiveButton("YES"){dialog, which ->
                // Do something when user press the positive button
                Toast.makeText(applicationContext,"Ok, we change the app background.",Toast.LENGTH_SHORT).show()

                // Change the app background color
                root_layout.setBackgroundColor(Color.RED)
            }


            // Display a negative button on alert dialog
            builder.setNegativeButton("No"){dialog,which ->
                Toast.makeText(applicationContext,"You are not agree.",Toast.LENGTH_SHORT).show()
            }


            // Display a neutral button on alert dialog
            builder.setNeutralButton("Cancel"){_,_ ->
                Toast.makeText(applicationContext,"You cancelled the dialog.",Toast.LENGTH_SHORT).show()
            }

            // Finally, make the alert dialog using builder
            val dialog: AlertDialog = builder.create()

            // Display the alert dialog on app interface
            dialog.show()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...