I am trying to make a stop watch application that when you press start it starts and when you press stop it stops. I am using a handler and runnable with post delay, but I want it to only post if the Stop button has not been pressed. This is the way I am talking about implementing what I am talking about.
if(!StopBClicked()){
handler.postDelayed(r, 1000);
}
This is what I have so far for making it a boolean thing.
public boolean StopBClicked() {
Button StopB = (Button)findViewById(R.id.StopB);
StopB.setOnClickListener(new View.OnClickListener(){
return true;
}
}
But as you might guess it doesn’t work. It is giving me an error at the “)” after OnClickListener(. I am a little new so I would appreciate a example code. Thank you.
Just run your action when the button is clicked.
Add this to your
onCreate: