我尝试使用处理程序,但它说'无法解析符号'处理程序''


糖果
2025-04-07 07:19:34 (1天前)

我该怎么做才能使用处理程序每​​ 2 秒更新一次 TextView,因为现在它出现了“无法解析符号“处理程序””

  1. int noStart = 20;
  2. int minus = 5;
  3. public void number(View view) {
  4. final TextView tx = (TextView) findViewById(R.id.number);
  5. if(noStart<0){
  6. new Handler().postDelayed(new Runnable() {
  7. public void run() {
  8. noStart -= minus;
  9. tx.setText(String.valueOf(noStart));
  10. }
  11. }, 2000);
  12. }
  13. }
3 条回复
  1. 1# 糖果 | 2022-01-18 11-18

    检查您的活动导入并将此行添加到类中:
    import android.os.*

  2. 2# 糖果 | 2022-01-18 11-18

    就我而言,我在外部类中引用了类 Handler 的常量,如下所示:

    1. import static *.MyHandler.MSG_WHAT_PING_NETWORK;
    2. public class OuterClass {
    3. // use MSG_WHAT_PING_NETWORK...
    4. // ...
    5. }
    6. class MyHandler extends Handler {
    7. public static final int MSG_WHAT_PING_NETWORK = 99;
    8. // ...
    9. }

    删除外部类中的导入可以解决问题。

登录 后才能参与评论