I need to hide a TextView after 10 seconds. I thought I could implement a Chronometer and when elapsed time is bigger than 10000 millis I hide the TextView. My problem is that the chronometer only ticks once and then stops. Any idea what I've missed ?
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();
}
Thank you Janusz for your help. The solution that works great now is:
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);