2

我尝试在我的新应用程序中使用 StaggeredGridView。一切正常。现在我想添加一个 HeaderView 和一个 FooterView,但这给了我以下错误:

java.lang.IllegalStateException: The content of the adapter has changed but ExtendableListView 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 ExtendableListView(2131165194, class com.tundem.numbersreloaded.view.NumbersGridView) with Adapter(class com.etsy.android.grid.HeaderViewListAdapter)]
            at com.etsy.android.grid.ExtendableListView.layoutChildren(ExtendableListView.java:557)
            at com.etsy.android.grid.StaggeredGridView.layoutChildren(StaggeredGridView.java:358)
            at com.etsy.android.grid.ExtendableListView.onLayout(ExtendableListView.java:513)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
            at android.view.Choreographer.doCallbacks(Choreographer.java:574)
            at android.view.Choreographer.doFrame(Choreographer.java:544)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

我在 AsynchTask 的 onPostExecute 方法中设置了适配器,该方法在我的 Activity 的 onCreate 中有它的 onExecute 方法。在启动异步任务之前,我还在 onCreateMethod 中添加了 Header 和 FooterView。

我也尝试从 runOnUiThread 运行它,如果我在 UI 线程中,我还通过 Looper.myLooper() == Looper.getMainLooper() 检查。任何提示我如何解决此问题的人。

4

2 回答 2

1

我已经自己找到了答案。

这不是我一直遇到的问题。这是 AndroidStaggeredGrid 当前存在的问题。已经有一个合并的 Pull-Request 有一个修复,但它还没有上传到 maven。

我指的是这两个提交:

现在的解决方案是自己构建库并将其发布到私有 maven 存储库,或者将项目包含为库项目!

于 2014-04-17T18:04:47.050 回答
0

您是否尝试过在 AsyncTask 的 onPostExecute 方法中调用 adapter.notifyDataSetChanged() ?

这个订单对我有用:

  • 在 onCreate 方法中添加页眉和页脚视图,然后设置适配器,然后执行 Async Task
  • 在 AsyncTask 的 onPostExecute 方法中,您将所有项目添加到您的适配器(addAll 或添加取决于 SDK 版本)并调用 adapter.notifyDataSetChanged()
于 2014-04-17T09:10:34.190 回答