3

I have a mutable list that changes each time the generate() function is called. What I'm trying to do is convert it to a string and set it to a TextView. The way I set the TextView below works for Integers but not for lists. It just does not display the contents of the list and I have no idea why it won't work. Instead the TextView2 does this: Genereated Numbers: []

    val text = findViewById<TextView>(R.id.textView)
    val text2 = findViewById<TextView>(R.id.textView2)

    var possibleInputs = mutableListOf(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

    fun generate() {
        var num = (0..20).shuffled().last()

        when {
            possibleInputs.size == 0 -> text.text = "Done"
            num in possibleInputs -> {
                text.text = "$num"
                text2.text = "Generated Numbers: $possibleInputs"
                possibleInputs.remove(num)
            }
            else -> generate()
        }
    }
Tad
  • 889
  • 9
  • 23
  • 1
    https://stackoverflow.com/questions/9668041/android-how-to-print-a-array-in-text-view-or-anything Please check if this helps – Dhaval Jardosh Oct 31 '18 at 14:38
  • @DhavalJardosh I guess I couldn't find that duplicate question because I was searching specifically for Kotlin and android, not java. – Tad Oct 31 '18 at 14:39
  • If you figured out the solution, it's better that you post the answer, as it will be more specific. :) – Dhaval Jardosh Oct 31 '18 at 14:46

1 Answers1

2

This is the code I used to fix it

for (i in 0 until possibleInputs.size) {
    text2.append(possibleInputs[i].toString())
    }
Tad
  • 889
  • 9
  • 23