Here I have created a method in DataBase helper(sqlite) to remove Items from RecyclerView. In the example code first i have created deleteCallDetail method and after then In Adpter class I have used ClickListener, so that when we click on cross(Image)item that item will be removed from the RecyclerView list.
Step(1)- Create query for remove item in DataBase Helper(sqlite)
public void deleteCallDetail(String number, String duration) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME, "CallNumber='" + number + "'and CallDuration='" + duration + "'", null);
db.close();
}
Step(2)Database Helper remove item Method call-
holder.cross.setOnClickListener(new AdapterView.OnClickListener() {
@Override
public void onClick(View v) {
// mListner.OnRemoveClick(position);
DatabaseHelper databaseHelper = new DatabaseHelper(v.getContext());
databaseHelper.deleteCallDetail(callData.getPhNumber(), callData.getCallDuration());
callDataList.remove(position);
notifyDataSetChanged();
}
});
0 Comment(s)