0

Possible Duplicate:
CountDownTimer- that the user increments. Issues

I have to make an application that allows the user to increment the time by +1, for every click of the button. Then after the button stops being clicked it waits for three seconds, then starts to countdown.

I've been pretty stuck then realized I might be able to implement this through a java action listener where I use something like this. I posted my code, this however doesn't work correctly - was just wondering if someone could lead me in the right direction.

Thank you

@SuppressWarnings("unused")
public class MainActivity extends Activity {

private static String TAG = "cs313f12p1a";
    Button stoptime;
    public TextView timedisplay;
    public myTimer wavetimer;
    private long millisInFuture;
    private long millisUntilFinished;
    private long countDownInterval;
    private long onclicktime;
    private WaveInterface model;
    public long counter;

    private boolean buttonClicked;
    private Thread thread;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);     
    stoptime = (Button) findViewById(R.id.button2);
    stoptime.setText("Stop Timer");
    timedisplay = (TextView) findViewById(R.id.mycounter);
    timedisplay.setText("Time Left: " + millisUntilFinished);
    wavetimer = new myTimer (millisInFuture, countDownInterval);
    counter = 01;
    final MainActivity MainActivity = this;


    stoptime.setOnClickListener(new OnClickListener(){

    public void onClick(View v) {
        if (!buttonClicked){
            counter++;
        } else {

            wavetimer.start();
        }

 }

    }});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
Community
  • 1
  • 1

2 Answers2

0

Well, looking at the code you've posted I think it will never work - you start your timer when the buttonClicked is true, but you never set it in that state.

Daniel Cisek
  • 931
  • 3
  • 9
  • 23
  • Oh crap, I didn't even see that. I declared it as false to test something out. I will edit that out and just declare it Boolean. –  Oct 10 '12 at 20:17
0

I have found a better solution for using a timer.

The way you are using it right now is wrong, check out this link:

how to change text in Android TextView

Community
  • 1
  • 1
meh
  • 22,090
  • 8
  • 48
  • 58