当我尝试删除列表中的项目时遇到问题。当我尝试删除列表时,它消失了,但是它们显示了一个新列表。情况看起来像这样。
下面我也提供了代码
adapter.setOnItemClickedCallback(object : ListOrderAdapter.OnItemClickCallback {
override fun onDecrementButtonClicked(orderMenu: OrderMenu, itemView: View, position: Int) {
var quantityChanged = (orderMenu.quantity)!!.minus(1)
itemView.tv_order_number.text = quantityChanged.toString()
Log.e("Position", position.toString())
if (quantityChanged > 0) {
updateData(quantityChanged, orderMenu)
} else {
listItem.remove(orderMenu)
recyclerView.removeViewAt(position)
adapter.notifyItemRemoved(position)
adapter.notifyItemRangeRemoved(position, listItem.size)
Toast.makeText(applicationContext, "Pesanan telah di hapus dari orderan", Toast.LENGTH_SHORT).show()
}
}
})
}
private fun updateData(quantityChanged: Long, orderMenu: OrderMenu) {
for (item in listItem){
if (item.name.equals(orderMenu.name)){
item.quantity = quantityChanged
}
}
}