这是我的计时器代码,其中显示了第一个时间值,但在单击工具栏后,文本视图未显示,而日志显示正确的值。
countDownTimmer = (TextView) findViewById(R.id.countDownTimmer);
timmermMin = getIntent().getStringExtra("timmermMin");
yourCountDownTimer = new CountDownTimer(Integer.parseInt(timmermMin) * 60000, 1000) {
public void onTick(long millisUntilFinished) {
seconds = (int) (millisUntilFinished / 1000);
hour = seconds / 3600;
minutes = (seconds % 3600) / 60;
seconds = seconds % 60;
countDownTimmer.setText("TIME : " + String.format("%02d", hour) + ":" + String.format("%02d", minutes)
+ ":" + String.format("%02d", seconds));
Log.e("Time",+hour + " " + minutes + " " + seconds + " ");
Log.e("millisUntilFinished", String.valueOf(millisUntilFinished));
milliSecondRemaining = String.valueOf(millisUntilFinished);
}
public void onFinish() {
countDownTimmer.setText("Time Up!");
}
}.start();
我的工具栏返回按代码是:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// todo: goto back activity from here
Intent intent = new Intent(TestSubjectActivity.this, TestSubjectActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("timmermMin",milliSecondRemaining);
startActivity(intent);
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这段代码:
yourCountDownTimer = new CountDownTimer(Integer.parseInt(timmermMin) * 60000, 1000) {
public void onTick(long millisUntilFinished) {
seconds = (int) (millisUntilFinished / 1000);
hour = seconds / 3600;
minutes = (seconds % 3600) / 60;
seconds = seconds % 60;
runOnUiThread(new Runnable() {
@Override
public void run() {
countDownTimmer.setText("TIME : " + String.format("%02d", hour) + ":" + String.format("%02d", minutes)
+ ":" + String.format("%02d", seconds));
}
});
Log.e("Time",+hour + " " + minutes + " " + seconds + " ");
Log.e("millisUntilFinished", String.valueOf(millisUntilFinished));
milliSecondRemaining = String.valueOf(millisUntilFinished);
}
public void onFinish() {
countDownTimmer.setText("Time Up!");
}
}.start();