Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

addAdapters 的问题 #24

Closed
kelvins22 opened this issue Mar 15, 2017 · 3 comments
Closed

addAdapters 的问题 #24

kelvins22 opened this issue Mar 15, 2017 · 3 comments
Labels

Comments

@kelvins22
Copy link

kelvins22 commented Mar 15, 2017

假设目前有这样的需求:
列表和头部的数据分开,头部数据请求优先于列表回来,为了不阻碍展示,先创建了头部相关的 adapters 并且 setAdapters,等列表数据回来以后再 addAdapters。
把 examples 里面 VLayoutActivity 的 StaggeredGridLayoutHelper adapter 通过 addAdapters 加入,会出现下面的问题:

java.lang.IllegalStateException: Cannot change whether this adapter has stable IDs while the adapter has registered observers.
at android.support.v7.widget.RecyclerView$Adapter.setHasStableIds(RecyclerView.java:5281)
at com.alibaba.android.vlayout.DelegateAdapter.addAdapters(DelegateAdapter.java:313)
at com.alibaba.android.vlayout.DelegateAdapter.addAdapters(DelegateAdapter.java:323)
at com.alibaba.android.vlayout.example.VLayoutActivity$13.run(VLayoutActivity.java:500)
求这种场景的使用姿势,谢谢~
@longerian
Copy link
Contributor

longerian commented Mar 15, 2017

先把 adapter 都加进去,然后通过 subAdapter 的 notifyDataSetChanged()方法刷新界面,这个 crash 我处理一下。

longerian added a commit that referenced this issue Mar 15, 2017
@kelvins22
Copy link
Author

谢谢指点,然后发现另外一个问题,addAdapters 中 for 循环里面 position 是不是需要递增,否则的话后面的 adapter 的顺序就倒过来了

@longerian
Copy link
Contributor

你说的对,我也修复了

@longerian longerian added the bug label Mar 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants