I try to use Alert Dialog to make category option. This will show option and let user choose from the option by clicking. After choosing, it will get the option and change the TextView string into the choosen option. After i run it, it show the AlertDialog, but it seems like it can't get my input, the TextView still the same.
this is my code:
private fun categoryDialog(){
val builder= AlertDialog.Builder(this)
builder.setTitle("Kategori Sampah").setItems(Constants.KATEGORI_BARANG){dialog,which ->{
val category= Constants.KATEGORI_BARANG[which]
val tv_kategori=findViewById<TextView>(R.id.tv_kategori)
tv_kategori.setText(category)
}}.show()
}
i call this function in onClickListener
tv_kategori.setOnClickListener{
categoryDialog()
}
I put my Constants.KATEGORI_BARANG in other file:
val KATEGORI_BARANG: Array<String> = arrayOf(
"Botol Plastik",
"Gelas Plastik",
"Bubble Wrap",
"Jerigen",
"Kantong Plastik",
"Jerigen",
"Sachet Plastik",
"Buku/Majalah",
"Kardus",
"Koran",
"Kertas Putih",
"Botol Kaca",
"Kaca",
"Kaleng",
"Pipa"
)
anyone know what i do wrong?
Thanks @Henry Twist. Turns out the problem was with the lamda. I'm following a tutorial with java language and when i try with kotlin i fail to manage the changes