mercredi 11 mars 2020

How to show all checkboxes in recyclerview?

I want to display all the checkboxes by long press, but only one is displayed There is a part of my adapter

override fun onBindViewHolder(holder: ViewHoldder, position: Int) {
    holder.textView?.text = lstWords[position].engWord
    holder.textView2?.text = lstWords[position].transWord
    holder.textView3?.text = lstWords[position].rusWord
    holder.checkBox?.setOnCheckedChangeListener(object : CompoundButton.OnCheckedChangeListener {
        override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
            val word = Words(
                lstWords[position].idWord!!,
                lstWords[position].engWord!!,
                lstWords[position].transWord!!,
                lstWords[position].rusWord!!,
                lstWords[position].check!!
            )
            if (holder.checkBox?.isChecked!!){
                words.add(word.idWord.toString())
                Log.d("MYTAG", "$words")
            }
            if (!holder.checkBox?.isChecked!!){
                words.remove(word.idWord.toString())
                Log.d("MYTAG", "$words")
            }
        }
    })
    holder.itemView.setOnLongClickListener {
        holder.checkBox?.visibility = CheckBox.VISIBLE
        true
    }
}

How to change all checkboxes?




Aucun commentaire:

Enregistrer un commentaire