The startButton has an onTouchListener that, when pressed, starts a media player (mp in my source) and makes the same button have a stop function to it.
For example:
The user hits the start button and the music plays. Then the user hits the same button (which now has a setText of “Stop”) to stop the music player.
Is it possible to has multiple onTouchListener(s) within a method?
startButton.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mp.start();
timeLeft.setText("Status: Initiated");
startButton.setText("Stop Dreaming");
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mp.stop();
}
});
This is what I currently have… How would I set this up correctly?
I suggest you use a toggle button for this endeavor:
More info on toggle buttons here: http://developer.android.com/guide/topics/ui/controls/togglebutton.html