我有根
FastAdapter
MultipleChoiceQuestionitem
延伸
AbstractBindingItem
RecyclerView
这个里面还有一个叫做
MultipleChoiceItem
我想把点击从
多回音项
快速适配器
所以我基本上可以知道用户选择了哪个选项。这是我试过的。
abstract class MultipleChoiceSelectionEventHook : CustomEventHook<MultipleChoiceQuestionItem>() {
override fun onBind(viewHolder: RecyclerView.ViewHolder): View? {
return if (viewHolder is BindingViewHolder<*> && viewHolder.binding is ItemMultipleChoiceQuestionBinding)
(viewHolder.binding as ItemMultipleChoiceQuestionBinding).recycler
else null
}
override fun attachEvent(view: View, viewHolder: RecyclerView.ViewHolder) {
((view as RecyclerView).adapter as FastAdapter<*>).onClickListener = { _,_,item,_ ->
if (item is MultipleChoiceItem) choiceSelected(item.id!!)
false
}
}
abstract fun choiceSelected(choiceId: String)
}
这在运行时不起作用,因为在这一点上
回收视图
没有适配器集,我们只有
View
布局中的类。因此我得到一个
NullPointerException
在
((view as RecyclerView).adapter
.
MultipleChoiceQuestionItem::bindView()
方法。如果这是可能的话。。。
我将事件挂钩添加到根fast适配器,如下所示。
fastAdapter.addEventHook(object : MultipleChoiceQuestionItem.MultipleChoiceSelectionEventHook() {
override fun choiceSelected(choiceId: String) {
TODO("Do something with this choice:$choiceId")
}
})