I am designing a simple app in which myfunction() is called when the start button is pressed. myfunction() takes a few seconds to complete. Right now when I press the Start Button, myfunction() runs for a few seconds and after it is complete, the text of the button changes to "Stop". I want the text of the button to change to "Stop" as soon as the "Start" Button is pressed and before the function is called.
This is my first time working with Android Studio and Java. Any help is appreciated.
I've attached the function which is called when the button is pressed.
public void buttonClick(View v) {
Button tv = (Button)findViewById(R.id.button1);
if(tv.getText() == "Start") {
tv.setText("Stop");
myfunction();
}
else {
tv.setText("Start");
}
}