我在项目中使用HeaderListView。它工作正常。但是在某个地方,当我尝试使用notifydatesetchanges时,它将引发IllegalStateException。仅当我尝试快速滚动列表视图时,才会发生这种情况。

这是堆栈跟踪

 05-12 12:03:42.641: E/AndroidRuntime(22291): 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. [in ListView(-1, class HeaderListView$InternalListView) with Adapter(class android.widget.HeaderViewListAdapter)]
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.widget.ListView.layoutChildren(ListView.java:1555)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.widget.AbsListView.onTouchMove(AbsListView.java:3549)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3424)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.View.dispatchTouchEvent(View.java:7736)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.View.dispatchPointerEvent(View.java:7916)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4031)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3910)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3510)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3479)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3586)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3487)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3643)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3510)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3479)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3487)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5728)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5659)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5630)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5808)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
 05-12 12:03:42.641: E/AndroidRuntime(22291):   at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiv


我尝试了许多解决方案,并进行了大量搜索,但没有找到任何可靠的解决方案。

这是我的代码。

HeaderListView listView;
MyAdapter myAdapter;
ArrayList<String> eventList = new ArrayList<String>();


第一次获取列表的代码。

private class GetList extends AsyncTask<String, Void, String> {

    ArrayList<String> loadMoreList;
    @Override
    public String doInBackground(String... params) {
        loadMoreList = WebFunctions.getEventList(params[0] ,params[1], params[2], params[3]);

        return null;
    }

    @Override
    public void onPreExecute() {

        }

    @Override
    public void onPostExecute(String string) {
        if(loadMoreList != null){
            if(loadMoreList.size() > 0){

                eventList.clear();
                eventList.addAll(loadMoreList);
                myAdapter = new MyAdapter(thisContext, eventList);
            }
      }
}


代码以获取更多列表项。

 private class LoadMoreList extends AsyncTask<String, Void, String> {

    ArrayList<String> loadMoreList;
    @Override
    public String doInBackground(String... params) {
        loadMoreList = WebFunctions.getEventList(params[0] ,params[1], params[2], params[3]);

        return null;
    }

    @Override
    public void onPreExecute() {

        }

    @Override
    public void onPostExecute(String string) {
        if(loadMoreList != null){
            if(loadMoreList.size() > 0){
                eventList.addAll(loadMoreList);
                myAdapter.notifyDataSetChanged();
        }
    }
}

最佳答案

实际的问题出在HeaderListView库中,但是现在该错误已得到解决。
您可以在此link中看到问题已解决。

关于java - java.lang.IllegalStateException:适配器的内容已更改,但HederListView没有收到通知,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23602702/

10-12 19:04