I'm trying to make a countdown timer. It works without a button but then it starts instantly so you can't enter a value for the start. Here is the java, as I said nothing appears in the logcat. The error occurs when the button is clicked. I would really appreciate it if you could have a look at it for me,
package timer.test;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class TimerTestActivity extends Activity {
TextView count;
EditText start;
Button begin;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
begin = (Button)findViewById(R.id.button1);
//count = (TextView)findViewById(R.id.TextView1);
begin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MyCount counter = new MyCount(5000,1000);
counter.start();
}
class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
count.setText("Finish");
}
@Override
public void onTick(long millisUntilFinished) {
count.setText(millisUntilFinished/1000 + "left");
}
}
});
}
}
The xml page only has a TextView, EditText and Button, let me know if it would help to see it too.
Thank you very much for any help you can give.
package timer.test;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class TimerTestActivity extends Activity {
TextView count;
EditText start;
Button begin;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
begin = (Button)findViewById(R.id.button1);
//count = (TextView)findViewById(R.id.TextView1);
begin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MyCount counter = new MyCount(5000,1000);
counter.start();
}
class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
count.setText("Finish");
}
@Override
public void onTick(long millisUntilFinished) {
count.setText(millisUntilFinished/1000 + "left");
}
}
});
}
}
The xml page only has a TextView, EditText and Button, let me know if it would help to see it too.
Thank you very much for any help you can give.