Question

I have problem with handler. After create i want to send message to handler, but method sendEmptyMessage() cannot resolve. 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);
Was it helpful?

Solution

java.util.logging.Handler is the wrong class to import. You want to make sure you import android.os.Handler

OTHER TIPS

I don't see why you cannot resolve the sendEmptyMessage method. 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 :

import android.os.Handler;

mHandler.sendEmptyMessage(0); is wrong, because there is no method:

 public void handleMessage(int m);

Must be:

 mHandler.sendEmptyMessage(null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top