例如,如果TextView
或RadioButton
出现在屏幕上,10秒后我们想要自动显示其他一些TextView
或RadioButton
。怎么做?
使用下面的代码,然后调用10秒以下的方法,然后根据您的要求更改textview:
static int SPLASH_TIME_OUT = 10000; // Declear variable
// Code in activity or fragment
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
}
}, SPLASH_TIME_OUT);
您可以使用CountDownTimer在每个10s此样本时更改布局:
private void countDownTimer(){
//10000 = 10s
new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
//Done 10s: code to change layout this
//And call this again
countDownTimer()
}
}.start();
}
你可以尝试下面的代码。
textView.setText("Your old text");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
textView.setText("Your new text");
}
}, 10 * 1000);