0

i'm to learning programing in kotlin and i practicing with the control flow (wile), the problem is that i want to appear ten number in my virtual device and just appear one.

This is the my code:

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    button.setOnClickListener {

        var num = ingrese_valor.text.toString().toInt()


        while (num < 10) {

            num++

            tv_resultad.text = ("" + num)

        }

    }

}

}

Exanple : enter image description here

1 Answers1

0

You need to get the previous text from the TextView and append it with new number.

replace tv_resultad.text = ("" + num) with this

tv_resultad.text = tv_resultad.text.toString().plus(num)
Atiq
  • 14,435
  • 6
  • 54
  • 69