is there a faster/simpler way to make this:? I'm creating a numpad in my Android App which I use 10 buttons for and a delete button. Right now I'm doing it like this but like this it's gonna take a lot of code.
num0.setOnClickListener(){
editTextNumberPassword.append("0")
}
num1.setOnClickListener(){
editTextNumberPassword.append("1")
}
num2.setOnClickListener(){
editTextNumberPassword.append("3")
}
CodePudding user response:
Add all views into a list and then use the index:
listOf(num0, num1, num2)
.withIndex()
.forEach { (index, view) ->
view.setOnClickListener { editTextNumberPassword.append("$index") }
}