gpt4 book ai didi

android - CountDownTimer 如何在 OnTick 方法中访问 UI?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:27 26 4
gpt4 key购买 nike

CountDownTimer 如何在 onTick 方法中访问 UI?

(new CountDownTimer(10000,1000){

@Override
public void onFinish() {
// TODO Auto-generated method stub

}

@Override
public void onTick(long millisUntilFinished) {
TextView tv = (TextView)findViewById(R.id.tvLCD);
tv.setText(Long.toString(millisUntilFinished));
}
}).start();

最佳答案

从@Sergey Glotov 给出的答案中的链接( GreCode - Handler )可以明显看出,倒数计时器根本不使用单独的线程。这就是您能够访问所有 UI 元素的原因。我不知道他们为什么使用处理程序。但它不会产生新线程。它在 UI 线程本身上运行。

关于android - CountDownTimer 如何在 OnTick 方法中访问 UI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6354740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com