我必须通过单击按钮来更改SelectionPredicates.createSelectSingleAnything()
和SelectionPredicates.createSelectSingleAnything()
。
当我在SelectionPredicates
上更改Runtime
时显示此错误
首先在onCreate()
中创建SelectionBuilder对象
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
selectionBuilder = SelectionTracker.Builder<Long>(
"mySelection",
recyclerView,
StableIdKeyProvider(recyclerView),
MyItemDetailsLookup(recyclerView),
StorageStrategy.createLongStorage()
)
tracker = customerBuild.build()
adapter.tracker = tracker
...
}
在selectoinBuilder
中,我没有在此处输入任何关于SelectionPredicate
的字样,因为当用户选择其中一个按钮时,它将配置为打开。
single.setOnClickListener {
tracker?.clearSelection()
tracker = selectionBuilder.withSelectionPredicate(
SelectionPredicates.createSelectSingleAnything()
).build()
adapter.tracker = tracker
}
multi.setOnClickListener {
tracker?.clearSelection()
tracker =selectionBuilder.withSelectionPredicate(
SelectionPredicates.createSelectAnything()
).build()
adapter.tracker = tracker
}
tracker?.addObserver(object : SelectionTracker.SelectionObserver<Long>() {
override fun onItemStateChanged(key: Long, selected: Boolean) {
super.onItemStateChanged(key, selected)
Log.i("Hello", "changes is index $key, and value is $selected")
}
})
您可以在GitHub上看到。谢谢!
答案 0 :(得分:1)
在selectionBuilder的StableIdKeyProvider中,将参数从recyclerView更改为adapter,因为keyProviders是选择键的源,也就是适配器。