Whenever I check the first item in the checklist, it checks some other items as well.
This is my onBindViewHolder method in the adapter class
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val itemText = reminderItemSet[position].item.toString()
holder.checkBox.isChecked = reminderItemSet[position].completion == true
if(holder.checkBox.isChecked){
holder.textView.apply{paintFlags = paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
text = itemText}
} else
holder.textView.apply{paintFlags = paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
text = itemText}
holder.checkBox.setOnCheckedChangeListener { buttonView, isChecked ->
mActivity.toggleCheck(reminderItemSet[position].item.toString(), isChecked)
}
if (reminderItemSet[position].ttid != "null") {
holder.playIV.visibility = View.VISIBLE
holder.infoIV.setOnLongClickListener {
mActivity.startStreaming(reminderItemSet[position])
}
} else {
holder.playIV.visibility = View.GONE
}
holder.infoIV.setOnClickListener {
mActivity.infoDialog(reminderItemSet[position])
}
holder.textView.setOnLongClickListener {
mActivity.removePendingitem(reminderItemSet[position].item.toString())
}
}
This is the method in main activity that loads the data from firebase
fun getTopLevelItems(): ArrayList<reminderItem> {
database.addValueEventListener(object : ValueEventListener {
@SuppressLint("NotifyDataSetChanged")
override fun onDataChange(dataSnapshot: DataSnapshot) {
itemList.clear()
for (i in dataSnapshot.children) {
val item = i.child("item").value.toString()
val owner = i.child("owner").value.toString()
val completion = i.child("completion").value.toString().toBoolean()
val date = i.child("date").value.toString()
val ttid = i.child("ttid").value.toString()
itemList.add(reminderItem(item, owner, completion, date, ttid))
}
mAdapter.notifyDataSetChanged()
}
override fun onCancelled(error: DatabaseError) {
Log.w("TAG", "Failed to read value.", error.toException())
}
})
return itemList
}
This is the method that appends the checks on firebase
fun toggleCheck(itemName: String, isChecked: Boolean) {
Log.i("TAGGER", "toggleCheck: $itemName to $isChecked")
database.child(itemName).child("completion").setValue(isChecked)
}
And here is the log for toggle check when I check "10 things I hate about you"
2022-09-03 14:44:06.035 19979-19979/com.example.vindication I/TAGGER: toggleCheck: 10 things I hate about you to true
2022-09-03 14:44:06.115 19979-19979/com.example.vindication I/TAGGER: toggleCheck: Shyam Singha Roy to true
2022-09-03 14:44:06.348 19979-19979/com.example.vindication I/TAGGER: toggleCheck: Shyam Singha Roy to true
2022-09-03 14:44:06.363 19979-19979/com.example.vindication I/TAGGER: toggleCheck: The Proposal to true
2022-09-03 14:44:06.491 19979-19979/com.example.vindication I/TAGGER: toggleCheck: The Proposal to true
2022-09-03 14:44:06.516 19979-19979/com.example.vindication I/TAGGER: toggleCheck: 我想你 to true
2022-09-03 14:44:06.621 19979-19979/com.example.vindication I/TAGGER: toggleCheck: 我想你 to true
Here's a link to the code
Here's a video showing the bug