Open CordyHo opened 4 years ago
能给个demo么?
能给个demo么?
链接: https://pan.baidu.com/s/1gpilUzlHbTI4aDRY-mindw 提取码: 4gte 有2个Adapter,一个原生写的,一个用BRVAH,你看看
我也是,getDefItemCount+1,就报空指针
你好,解决了吗
你好,解决了吗?我也遇到同样的问题了
你好,解决了吗
没,最新版还是空指针
你好,解决了吗?我也遇到同样的问题了
没,最新版还是空指针
解决了吗😂😂😂
需要重写getItemViewType方法呀
private val adapter by lazy { object : BaseQuickAdapter<Int, BaseViewHolder>(R.layout.item_layout) { override fun convert(helper: BaseViewHolder?, item: Int?) { helper?.itemView?.apply { textView.text = "hello world$item" } }
override fun getItemCount(): Int {
return Int.MAX_VALUE
}
override fun getItem(position: Int): Int? {
return data[position % data.size]
}
override fun getItemViewType(position: Int): Int {
var count = headerLayoutCount + data.size
if (count <= 0) {
count = 1
}
return super.getItemViewType(position % count)
}
}
}
可以了,是什么原理啊?
用的最新版,为啥我已经重写了这三个方法,还是报空指针?
而且是照着楼上粘的代码。。
解了吗
代码:
错误信息: kotlin.KotlinNullPointerException at com.chad.library.adapter.base.BaseQuickAdapter.onCreateViewHolder(BaseQuickAdapter.kt:231) at com.chad.library.adapter.base.BaseQuickAdapter.onCreateViewHolder(BaseQuickAdapter.kt:75) at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
这是我用原生Adaoter写法,可以正常运行:
`
`