I want to create alert dialog items. Here is my code.
val colors = arrayOf("Red","Green","Blue")
val builder = AlertDialog.Builder(this)
builder.setTitle("Pick a color")
builder.setItems(colors) {_,_ ->
Toast.makeText(this,"Red Color",Toast.LENGTH_LONG).show()
Toast.makeText(this,"Green Color",Toast.LENGTH_LONG).show()
Toast.makeText(this,"Blue Color",Toast.LENGTH_LONG).show()
}
builder.show()
}
}
In result, an alert dialog shows with 3 selections red, green and blue. But the problem is if I click on for example red color, so it shows three Toasts also if I click the blue/green color it shows the same. So how can I show a specific Toast on specific color select?