0

My current scripts are

fun addRow(text: String, rowNum: Int){
    val textViewNm: TextView = TextView(this.context)
    textViewNm.text = text
    textViewNm.gravity = Gravity.CENTER
    textViewNm.id = rowNum
    textBox.addView(textViewNm)
}

I'd like to callback and control textViews made by "addRow" function.

However I don't know how to call them back with ID (textViewNm.id = rowNum).

nothing showed when I tried

textViewNm.1 ,2 ,3 // which was rowNum
lacuna
  • 3
  • 2

1 Answers1

0
textViewNm.1 ,2 ,3 // which was rowNum

this won't work, because there's no property on a textView which is called 1, 2 or 3, etc.

that would be the same as using

textViewNm.SomeRandomPropertyWhichDoesNotExist

you should probably make use of another method to find these views, perhaps using findViewById or finding by tag


you could also consider keeping these dynamic components inside an array list and then iterating over this list

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
  • Thanks. fully understood. I will try "findViewById". -----> updated ----> it works. I can approach them using "textBox.findViewById(addCounter).text" – lacuna Feb 17 '21 at 13:25
  • you should have a look at the tag approach i added in my answer, you might find success with that, i simply wrote this answer to explain to you why it wouldn't work – a_local_nobody Feb 17 '21 at 13:26