如何从回收器视图中删除项目?
我有以下代码
在中
class LibraryAdapter(val list: ArrayList<Book>): RecyclerView.Adapter<LibraryAdapter.ViewHolder>() {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.removeBtn.setOnClickListener {
this.removeItem(position)
MUser.removeFromLibrary(list[position].id)
}
然后我有功能
fun removeItem(position: Int) {
list.removeAt(position)
notifyItemRemoved(position)
}
也许可以试试这个:
fun removeItem(position: Int) {
list.removeAt(position)
notifyDataSetChanged()
}