Как выбрать кнопку с идентификатором в Kotlin - PullRequest
0 голосов
/ 01 апреля 2020

Привет, я генерирую таблицу с этим кодом:

fun createTable(rows: Int, cols: Int) {
    contor_id = 0

    for (i in 0 until rows) {

        val row = TableRow(this)
        row.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT)

        for (j in 0 until cols) {
            val button = Button(this)
            button.apply {
                id=contor_id
                setTextColor(Color.WHITE)
                layoutParams = TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT)
                text = "R $i C $j"
            }
            println(button.id)
            row.addView(button)
            contor_id++
        }
        tableLayout.addView(row)
    }
    linearLayout.addView(tableLayout)
}

Я хочу сначала выбрать кнопки (1 на 1), чтобы изменить фон, но я не могу. Как я могу это сделать?

...