我需要在 10 秒后隐藏一个 TextView。我想我可以实现一个 Chronometer,当经过的时间大于 10000 毫秒时,我隐藏了 TextView。我的问题是计时器只滴答一次然后停止。知道我错过了什么吗?
Activity ctx = this;
...
private void ShowText(String message)
{
txtProceed.setText(message);
txtProceed.setVisibility(View.VISIBLE);
chronoHideText = new Chronometer(ctx);
chronoHideText.setOnChronometerTickListener(new OnChronometerTickListener()
{
public void onChronometerTick(Chronometer arg0) {
long elapsed = SystemClock.elapsedRealtime() - chronoHideText.getBase();
Log.i("Chrono",String.valueOf(elapsed));
if (elapsedTime>10000)
{
txtProceed.setVisibility(View.INVISIBLE);
chronoHideText.stop();
}
}
}
);
chronoHideText.setBase(SystemClock.elapsedRealtime());
chronoHideText.start();
}
感谢 Janusz 的帮助。现在效果很好的解决方案是:
Handler splashHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
//remove SplashScreen from view
txtProceed.setVisibility(View.INVISIBLE);
break;
}
super.handleMessage(msg);
}
};
Message msg = new Message();
msg.what = 0;
splashHandler.sendMessageDelayed(msg, 10000);