Question Kotlin change button text to Start and Stop

salm2s

Honorable
Jul 21, 2017
266
6
10,815
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

Honorable
Jul 21, 2017
266
6
10,815
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()