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

BaseQuickAdapter继承传入泛型VH,以便使用RecyclerView重载方法onViewAttachedToWindow、onViewRecycled等 #3834

Open
skyCracks opened this issue Dec 23, 2023 · 1 comment

Comments

@skyCracks
Copy link

目前源码中BaseQuickAdapter中实现:
abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(
open var items: List = emptyList()
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

}
adapter重载onViewRecycled方法时:
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
super.onViewRecycled()
}
这样需要对holder进行转换才能得到对应的ViewBinding,建议继承RecyclerView.Adapter和之前版本实现一样传入泛型VH,改成:
abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(
open var items: List = emptyList()
) : RecyclerView.Adapter() {

}

@limuyang2
Copy link
Collaborator

这个实在没有办法,因为 BaseQuickAdapter 还有内部的 StateLayoutVH,不能在class处指定为泛型VH

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