jeudi 5 décembre 2019

Select only one check box ; RecyclerView; Kotlin

It's my code and I want to choose only one checkbox, and if another checkbox is selected i want that this convert in uncheked


class AuthorizationFormAdapter(lista: List<Procedures>?) : RecyclerView.Adapter<AuthorizationFormAdapter.ViewHolder>() {

    val lista: List<Procedures>? = lista
    lateinit var array: BooleanArray

    class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
        val text: TextView? = null
        val checkBox: CheckBox? = null
    }

    override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.card_authform, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return lista!!.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.view.auth_name.text = lista!![position].name_procedure
        holder.view.cb_auth.setOnClickListener {
            if (holder.view.cb_auth.isChecked) {
                holder.view.cb_auth.isSelected = true
            } else if (!holder.view.cb_auth.isChecked) {
                holder.view.cb_auth.isChecked = false
            }
        }

    }
}

And Xml is only one checkBox and textView in my card I will be very grateful with your help




Aucun commentaire:

Enregistrer un commentaire