Question

I am attempting to edit a ListView on a regular interval using TimerTask:

public static TimerTask mTtRefreshUpload = new TimerTask() {
            @Override
            public void run() {
                    ((Activity) context).runOnUiThread(new Runnable() {
                        @Override
                            public void run() {
                                // Should create new adapter in here, not in Background Thread
                                refreshStatusItemAdapter = new RefreshStatusItemAdapter(context, R.layout.simple_list_item_upload, Constants.mLlItems);
                            }
                        });
            }
};

But I get this error:

java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes.

I have looked into the documentation for TimerTask, but this has not helped.

What is the problem? Does it have to do with cross threading problems?

Était-ce utile?

La solution

I got same problem like you,

I think if you used runOnUIThread, it still always works for you.

Must define runOnUIThread in your Constructor, onPreExecute, onPostExecute.

Specially is your ListView, must define in runOnUIThread too.

p/s : The last time, I forgot define Initializing List View in runOnUiThread.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top