addHeaderView和addFooterView后StaggeredGridView setAdapter [英] StaggeredGridView setAdapter after addHeaderView and addFooterView
问题描述
我试着在我的新应用程序了使用StaggeredGridView。一切工作正常。现在我想添加一个HeaderView和FooterView,但是这给了我以下错误:
I try to use StaggeredGridView in my new applicaiton. Everything is working fine. Now i want to add a HeaderView and a FooterView, but this gives me following error:
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)
我有它在我的活动的OnCreate onExecute方法的AsynchTask的onPostExecute方法设置的适配器。
我还加了onCreateMethod页眉和FooterView之前,我开始了AsynchTask。
I set the Adapter in the onPostExecute method of an AsynchTask which has it's onExecute method in the onCreate of my Activity. I also add the Header and FooterView in the onCreateMethod before i start the AsynchTask.
我也尝试从runOnUiThread运行它,我已经通过Looper.myLooper还检查()== Looper.getMainLooper()如果我在UI线程。任何人只要有提示我怎么能解决这个问题。
I've also tried to run it from the runOnUiThread and i've also checked via Looper.myLooper() == Looper.getMainLooper() if i'm in the UI Thread. Anyone with hints how i can solve this issue.
推荐答案
我找到了答案已经在我自己的。
I found the answer already on my own.
这不是我的问题,我把所有的时间。这是AndroidStaggeredGrid目前有一个问题。
目前已经是一个合并拉请求与修复,但它没有被上传到尚未有Maven。
It was not my issue i had all the time. It's a issue the AndroidStaggeredGrid currently has. There's already a merged Pull-Request with a fix but it was no uploaded to maven yet.
我指的是这两个承诺:
的https://github.com/etsy/AndroidStaggeredGrid/commit/2fce475c197bb18871d2a1076e259a57d8513104
对于现在的解决方案是建立在你自己的图书馆,它发布到一个私人的Maven回购,或包括项目的库项目!
For now the solution is to build the library on your own and publish it to a private maven repo, or you include the project as library project!
这篇关于addHeaderView和addFooterView后StaggeredGridView setAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!