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

getPosition() 方法不能获得正确的 Position #57

Closed
zhangls2014 opened this issue Jan 7, 2017 · 4 comments
Closed

getPosition() 方法不能获得正确的 Position #57

zhangls2014 opened this issue Jan 7, 2017 · 4 comments
Labels

Comments

@zhangls2014
Copy link

Q: 如何在 ItemViewProvider 中获取到 item position? A: 从 v2.3.0 版本开始,只需要在你的 ItemViewProvider 子类里调用 getPosition() 方法即可。如果低于 v2.3.0 版本,可以调用 holder.getAdapterPosition() 获得同样结果。
在我使用 v2.3.4 时发现,他们俩并不一致
onClick: ===AdapterPosition:0===Position:1
onClick: ===AdapterPosition:1===Position:1
onClick: ===AdapterPosition:2===Position:2
onClick: ===AdapterPosition:3===Position:3
onClick: ===AdapterPosition:4===Position:4
onClick: ===AdapterPosition:5===Position:5
onClick: ===AdapterPosition:0===Position:0
onClick: ===AdapterPosition:1===Position:0
onClick: ===AdapterPosition:2===Position:0
onClick: ===AdapterPosition:2===Position:0
onClick: ===AdapterPosition:3===Position:3
onClick: ===AdapterPosition:3===Position:3
onClick: ===AdapterPosition:21===Position:22
onClick: ===AdapterPosition:22===Position:22
onClick: ===AdapterPosition:22===Position:22
onClick: ===AdapterPosition:23===Position:24
onClick: ===AdapterPosition:23===Position:24
这是我随手打印的日志

@drakeet
Copy link
Owner

drakeet commented Jan 7, 2017

请贴出你的相关代码。

@zhangls2014
Copy link
Author

@drakeet
Copy link
Owner

drakeet commented Jan 7, 2017

感谢反馈,这确实是一个 BUG!getPosition() 如果没有马上消费,确实会存在被新的 item 绑定上新的位置导致旧的 item view provider getPosition() 不正常。建议先用 holder.getAdapterPosition() 替代,抱歉!

@drakeet
Copy link
Owner

drakeet commented Jan 7, 2017

已经修复和发布更新:https://github.com/drakeet/MultiType/releases/tag/v2.3.5

@drakeet drakeet closed this as completed Jan 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants