Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSecondaryAdapter().getItems() 获取实体类强转报错 #37

Closed
p7nkie opened this issue Sep 15, 2020 · 7 comments
Closed

getSecondaryAdapter().getItems() 获取实体类强转报错 #37

p7nkie opened this issue Sep 15, 2020 · 7 comments

Comments

@p7nkie
Copy link

p7nkie commented Sep 15, 2020

你好
List<***> items = linkage.getSecondaryAdapter().getItems();
在获取适配器中的数据后遍历报错:
java.lang.ClassCastException: com.kunminx.linkage.bean.DefaultGroupedItem cannot be cast to ***
这种错误,得不到想要的实体类
可以给解答一下吗

@p7nkie p7nkie changed the title getSecondaryAdapter().getItems() 获取类型强转错误 getSecondaryAdapter().getItems() 获取实体类强转报错 Sep 15, 2020
@KunMinX
Copy link
Owner

KunMinX commented Sep 15, 2020

@p7nkie
请检查实体类的继承关系。
所有联动逻辑都是基于 BaseGroupedItem 来控制,
所以项目中使用的 GroupedItem 例如 DefaultGroupedItem,须继承于 BaseGroupedItem。
具体可参考项目中的示例。

@p7nkie
Copy link
Author

p7nkie commented Sep 15, 2020

可是都按照demo继承过了呀,列表都可以正常显示
就是获取数据的时候会出现这种错误
很苦恼@@

@KunMinX
Copy link
Owner

KunMinX commented Sep 15, 2020

@p7nkie
不需要强转。xxxGroupedItem 继承于 BaseGroupedItem(注意是 BaseGroupedItem 不是 DefaultGroupedItem),拿到 xxxGroupedItem 就可以使用。

@p7nkie
Copy link
Author

p7nkie commented Sep 16, 2020

就是继承的BaseGroupedItem
不强转的话出来的是Object对象 用不了呀

@p7nkie p7nkie closed this as completed Sep 16, 2020
@p7nkie p7nkie reopened this Sep 16, 2020
@p7nkie
Copy link
Author

p7nkie commented Sep 16, 2020

你好 发现问题了
为什么框架最后会加一条DefaultGroupedItem 这个数据呢?
还有最后的The End 怎么去掉呀

@KunMinX
Copy link
Owner

KunMinX commented Sep 16, 2020

@p7nkie
the end 是为了规避联动列表在产品层面的先天缺陷,
具体可翻看之前的 issue,
如不需要,可在 SecondaryAdapterConfig 中为 getFooterLayoutId 传个空白 view 的 layout 的 id,
具体参考示例。

@p7nkie
Copy link
Author

p7nkie commented Sep 16, 2020

好的 非常感谢!!!

@p7nkie p7nkie closed this as completed Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants