[SOLVED] Kotlin change button text to Start and Stop

salm2s

Respectable
Jul 21, 2017
252
4
1,815
9
Hi there,

I am relatively new to developing an android app and wanted to make my button change text from Start to Stop, so I did the following:

Code:
start_button.setOnClickListener {

    fun setStop() {
    if (start_button.text == "Start") {
        start_button.setText("Stop")
    }
    }
    setStop()
However, I am confused and struggling as to how I can then change the text back from Stop to Start and alternate it from Start to Stop and so on.

Is there any way I can do this?

Thanks,
salm2s
 

salm2s

Respectable
Jul 21, 2017
252
4
1,815
9
Never mind, I found a solution

Code:
start_button.setOnClickListener {

    fun setStop() {
    if (start_button.text == "Start") {
        start_button.setText("Stop")
    }
    else if (start_button.text == “Stop”) {
          start_button.setText(“Start”)
   }
    }
    setStop()
 

salm2s

Respectable
Jul 21, 2017
252
4
1,815
9
Never mind, I found a solution

Code:
start_button.setOnClickListener {

    fun setStop() {
    if (start_button.text == "Start") {
        start_button.setText("Stop")
    }
    else if (start_button.text == “Stop”) {
          start_button.setText(“Start”)
   }
    }
    setStop()
 

ASK THE COMMUNITY

TRENDING THREADS