简体   繁体   English

处理程序sendEmptyMessage()无法解析

[英]Handler sendEmptyMessage() cannot resolve

I have problem with handler. 我有处理程序问题。 After create i want to send message to handler, but method sendEmptyMessage() cannot resolve. 创建后,我想向处理程序发送消息,但是方法sendEmptyMessage()无法解析。 Handler must to update custom list adapter. 处理程序必须更新自定义列表适配器。

There is my code: 有我的代码:

private Handler mHandler;

mHandler = new Handler() {
        @Override
        public void close() {}

        @Override
        public void flush() {}

        @Override
        public void publish(LogRecord record) {}

        public void handleMessage(Message m)
        {
            catalogAdapter.notifyDataSetChanged();
        }
    };
mHandler.sendEmptyMessage(0);

java.util.logging.Handler is the wrong class to import. java.util.logging.Handler是错误的导入类。 You want to make sure you import android.os.Handler 您要确保导入android.os.Handler

I don't see why you cannot resolve the sendEmptyMessage method. 我不明白为什么您不能解决 sendEmptyMessage方法。 Maybe you have got a wrong import, check that. 也许您导入错误,请检查一下。

On a side note, you just need to post a message to you handler as so : 附带一提,您只需要向处理程序发布一条消息,如下所示:

new Handler(Looper.getMainLooper()).post(
 new Runnable() {
    @Override
    public void run() {
         catalogAdapter.notifyDataSetChanged();
    }
});

Or even maybe create a background Thread. 甚至可能创建一个后台线程。

As Massimo stated, your import should be : 正如Massimo所说,您的导入应为:

import android.os.Handler;

mHandler.sendEmptyMessage(0); is wrong, because there is no method: 是错误的,因为没有方法:

 public void handleMessage(int m);

Must be: 一定是:

 mHandler.sendEmptyMessage(null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM