从pagedList适配器调用接口-Android Kolin



如何在android kotlin中从pagedList回收器适配器调用接口?Please ehelp

您必须以某种方式将接口作为参数传递,一种方法是在构造函数上传递

class YourAdapterImplementation(
private val delegate: YourDelegateInterface
) : PagedListAdapter<YourModelClass, YourViewHolderClass>(
yourDiffCallback
) {
//... the rest of the mandatory code
onBindViewHolder(...) {
holder.someView.setOnClickListener {
delegate.someMethod(...)
}
}
}

然后安装是这样的,可能是在一个片段上

class YourFragment : Fragment, YourDelegateInterface {
onViewCreated() {
//the view code
val adapter = YourAdapterImplementation(this)
recycler.adapter = adapter
}
//the interface methods fully implemented
override someMethod(...) {....}
}

最新更新