I have list of items inside of recyclerview, and they are multiple selectable.
I want to have select button to select all, and if selected deselect all. I didn\'t se
There is no need to maintain another list with selected items. You need to create a method to set a flag and in the onBindViewHolder method just check for that flag. Something like this:
class MyAdapter(val context: Context): RecyclerView.Adapter() {
val mItems = mutableListOf()
private var selectAllItems: Boolean = false
fun updateList(list: List) {
mItems.addAll(list)
notifyDataSetChanged()
}
fun selectAllItems(selectAll: Boolean){
selectAllItems = selectAll
notifyDataSetChanged()
}
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val pos = viewHolder.adapterPosition
viewHolder.checkbox.isSelected = selectAllItems
}
class ViewHolder(val view: View): RecyclerView.ViewHolder(view) {
val checkbox: Checkbox = view.myCheckBox
}
}