我有一個應用程序,其中包含用於將數據從sqlite數據庫填充到recyclerview的適配器recyclerview。問題是,當我從RecyclerView刪除項目它不更新recyclerview。如何在android中更新recyclerview?
代碼: -
public void onClick(View v) {
String title;
title = modelList.get(position).getNotiifcationTitle();
notificationDBHelper.removeSingleNotification(title);
modelList.remove(position);
notifyItemRemoved(position);
modelList.clear();
//Updating ArrayList
modelList = notificationDBHelper.getAllNotificationsData();
swapItems(modelList);
//Setting deleted notification count
notificationDBHelper.insertNotificationDeleteCount(1);
}
添加swapItems方法 –
mAdapter.notifyDataSetChanged();或者在從數據庫再次加載數據之後執行刪除操作時,調用用於將數據附加到recyclerview的方法。 –