I'm trying to instantiate a large number (~600) onclick listeners for a large grid of buttons. I've created a function that stores the id's of each square in a list called squareList, in which each square is assigned a string value id (sq000, sq001, sq002)
I'd like to create a for loop that pulls the id of each square and then creates an onClicklistener, sort of like:
fun createSquareListeners(listOfSquares: MutableList<String>)
{
for(square in listOfSquares)
{
square.setOnClickListener{ //Do Something}
}
}
The other way I thought of implementing this was to write a single onClick function, and attach it to each button in the xml file, but I'm not really sure what's possible as I'm quite new to Kotlin/Java