• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Error on button click but no logcat

ktUK

Newbie
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.
 
BUMP - Still don't have a solution to this, if nobody can answer my question directly, is there a better way of building the timer?

Thanks
 
CountDownTimer uses a seperate thread, and you cant change UI elements outside of the UI thread. What you need to do is create a Handler object and then post message back to the UI thread, telling it to change the TextViews text.
 
Back
Top Bottom