Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace a button with another under android 4.0

I have a "start" button on my content view, i want to replace it with a "stop" button when clicking on it.

i have already defined a "start" and a "stop" button in xml , what should i do next? thanks a lot!

like image 941
WoooHaaaa Avatar asked Sep 28 '26 23:09

WoooHaaaa


1 Answers

You need a reference to your button in the code:

Button stop = (Button) findViewById( R.id.stopButton );
Button start = (Button) findViewById( R.id.startButton );

Add onClickListeners for both and when start is clicked you add these lines:

start.setVisibility( View.GONE );
stop.setVisibility( View.VISIBLE );

In stops onClickListener you do the opposite:

start.setVisibility( View.VISIBLE );
stop.setVisibility( View.GONE );

Or you could just let one Button handle both start and stop and just change the text of it.

like image 177
kaspermoerch Avatar answered Sep 30 '26 12:09

kaspermoerch