[英]I tried using a handler, but it said 'cannot resolve symbol"Handler"'
What do i do to be able to use a handler to update my TextView every 2 secs because right now it comes up with 'cannot resolve symbol"Handler"'我该怎么做才能使用处理程序每 2 秒更新一次 TextView,因为现在它出现了“无法解析符号“处理程序””
int noStart = 20;
int minus = 5;
public void number(View view) {
final TextView tx = (TextView) findViewById(R.id.number);
if(noStart<0){
new Handler().postDelayed(new Runnable() {
public void run() {
noStart -= minus;
tx.setText(String.valueOf(noStart));
}
}, 2000);
}
}
检查您的活动导入并将此行添加到类中:
import android.os.*
In my case, i refer to a constant of class Handler in outer calss, see as below:就我而言,我在外部类中引用了类 Handler 的常量,如下所示:
import static *.MyHandler.MSG_WHAT_PING_NETWORK;
public class OuterClass {
// use MSG_WHAT_PING_NETWORK...
// ...
}
class MyHandler extends Handler {
public static final int MSG_WHAT_PING_NETWORK = 99;
// ...
}
remove the import in outer class can solve the problem.删除外部类中的导入可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.