I want to implement this UI to make the user select one branch at a time. What I'm doing now is setCompoundDrawablesWithIntrinsicBounds for the text in each item when the user selects it.
The issues are "If I select item number 1 and then selected item number 4, how can I remove the selection from the item number 1? I don't want to click the item number 1 again to remove the selection"
Note that this screen makes the user select only one item.
This is my code in Kotlin But it is OK if you suggest a solution in JAVA:
var selectedBranch = false
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.packageNumber.text = branches?.get(position)?.nameEn ?: ""
check = ContextCompat.getDrawable(context, R.drawable.ic_select_branch)
holder.itemView.setOnClickListener {
if(!selectedBranch) {
holder.packageNumber.setCompoundDrawablesWithIntrinsicBounds(null, null, check, null)
selectedBranch = true
}
else {
holder.packageNumber.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
selectedBranch = false
}
}
}