私は、カウンタ(秒と分をカウントする)を持っていて、毎秒ディスプレイ上でそれを更新しようとしています。Android:タイマーでXML要素を変更する
私はActivity
を拡張私のクラスのonCreate
にこのコードを持っている:
timeOnCall = (TextView) findViewById(R.id.time);
minutes = seconds = 0;
timeOnCall.setText(minutes + ":" + seconds);
// Implements the timer
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
++seconds;
if (seconds == 60) {
seconds = 0;
++minutes;
}
// Display the new time
timeOnCall.setText(minutes + ":" + seconds);
}
}, 1000, 1000);
は残念ながら、私は次のエラーを取得する:ビュー階層を作成し
android.view.ViewRoot$CalledFromWrongThreadException:
だけのオリジナルthread
は触れることができますその見解。
これは既にonCreate()
メソッドにあるので、これを修正する方法がわかりません。誰かが解決策を知っていますか?
ありがとうございます!非常に便利! – James