2

Intuitivly, I know, when it throws the IllegalStateException. But in my case, I can't, though, probably guess, where is trouble in the source. I dare say, trouble lines are there:

private class LoadMoreDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
        if (isCancelled()) {
            return null;
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        OFFSET = OFFSET + COUNT;
        getWallsData();
        return null;
    }
    @Override
    protected void onPostExecute(Void result) { 

        mPostListAdapter.notifyDataSetChanged();                
        wallPostsList.onLoadMoreComplete();
        super.onPostExecute(result);
    }
    @Override
    protected void onCancelled() {
        wallPostsList.onLoadMoreComplete();
    }

there's a logcat message:

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. [in ListView(2131099757, class com.costum.android.widget.LoadMoreListView) with Adapter(class android.widget.HeaderViewListAdapter)]
Marat
  • 94
  • 11

1 Answers1

0

The problem is fixed:the answer was found there ! what I did? I have added, the switcher, Boolean LOADMORE SWITCHER=false; as global visibility and replaced mPostListAdapter.notifyDataSetChanged(); from doInBackground() to getWallsData().

private Boolean LOADMORE SWITCHER=false;
....
private class LoadMoreDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
        if (isCancelled()) {
            return null;
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        OFFSET = OFFSET + COUNT;
        LOADMORE=true;
        getWallsData();
        return null;
    }
    @Override
    protected void onPostExecute(Void result) { 

       // mPostListAdapter.notifyDataSetChanged(); was replaced to getWallsData() body
        wallPostsList.onLoadMoreComplete();
        super.onPostExecute(result);
    }
    @Override
    protected void onCancelled() {
        wallPostsList.onLoadMoreComplete();
    } 
}
.....
getWallsData(){
     ...
     if(LOADMORE){
          mPostListAdapter.notifyDataSetChanged();
          LOADMORE=false;


     }
}

I'm very-very glad to say: I haven't this problem anymore:

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. [in ListView(2131099757, class com.costum.android.widget.LoadMoreListView) with Adapter(class android.widget.HeaderViewListAdapter)] 
Community
  • 1
  • 1
Marat
  • 94
  • 11