以下はカウントダウンタイマーを使用するプログラムですが、エミュレータでプログラムを起動すると、というエラーメッセージが表示されます "申し訳ありませんAndroidTestTimer(プロセスandroid.test.timer)プロセスが予期せず停止しました。に強制終了ボタンがあります。AndDroidのCountDownTimerの使い方は?
以下はコードです。
package android.test.timer;
import android.os.CountDownTimer;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class AndroidTestTimerActivity extends Activity {
/** Called when the activity is first created. */
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.time_textview);
tv.setText("Default!");
MyTimer tim = new MyTimer(6000,1000);
tim.start();
}
public class MyTimer extends CountDownTimer {
public MyTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
tv.setText("changed by the constructor");
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
tv.setText("changed by the onFinish");
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
tv.setText("time: " + millisUntilFinished);
}
}
}
oncreate部分では、次の行を使用します。tv =(TextView)findViewById(R.id.time_textview);テキストビューの代わりにtv =(TextView)findViewById(R.id.time_textview); –