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

在 ConcatAdapter 中,itemViewType获取错误导致的崩溃 #317

Open
limuyang2 opened this issue Apr 15, 2021 · 6 comments
Open

在 ConcatAdapter 中,itemViewType获取错误导致的崩溃 #317

limuyang2 opened this issue Apr 15, 2021 · 6 comments

Comments

@limuyang2
Copy link

在 ConcatAdapter 中,MultiTypeAdapter 通过

types.getType<Any>(viewHolder.itemViewType)

在某些情况下会导致崩溃,出现数组越界,因为获得的 viewHolder.itemViewType 并不稳定,不会与 getItemViewType()返回值一一对应。

必须将 ConcatAdapter 配置中的 isolateViewTypes 参数设置为false(其默认值为 true)。但是设置为false之后,就会导致 ConcatAdapter 中所有 子AdapterViewHolder公用一个池子,不进行内部隔离。那这种就需要使用者,手动保持 每一个子AdaptergetItemViewType()返回值的唯一性。

个人认为,ConcatAdapter 默认会进行 ViewHolder的 itemType 隔离,那可能内部对ItemViewType进行了某种操作

@limuyang2
Copy link
Author

官方的写法是类似这样的:

when (holder) {
                is AHolder -> (holder as AHolder).bind(.....)
                is BHolder -> (holder as BHolder).bind(.....)
            }

但是本库极度依赖holder.itemViewType,尝试修改都没找到好的方式

@drakeet
Copy link
Owner

drakeet commented Apr 16, 2021

感谢反馈,目前不建议和 ConcatAdapter 一起使用,待近期适配 RV 1.2.0.

@drakeet
Copy link
Owner

drakeet commented Jun 3, 2021

看看是否和这个 issue 有关:https://issuetracker.google.com/issues/187339376

@cooliceman
Copy link

这个问题有新的进展么?
通过viewHolder的itemView添加自定义tag来保存multiTypeAdapter的viewType,取值时也通过tag来取值,规避viewholder.itemViewType和实际不一致问题.

@530l
Copy link

530l commented Aug 19, 2022 via email

@kolyneh
Copy link

kolyneh commented Jun 9, 2023

同问,需要与ConcatAdapter一起使用,尝试各种方法无果。

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

5 participants