My problem is that if I try to delete an item on my ListView
, all the data will be deleted to on both listview and my firebase realtime database. All I want is, if I long click an item, only that item will be removed, not all of them on the ListView
. Thank you. Any help is appreciated
This is what I declare:
MatkulAdapter matkulAdapter = null;
Matkul matkul;
DatabaseReference root = FirebaseDatabase.getInstance().getReference();
DatabaseReference dbReference = root.child("MataKuliah");
This is the code to delete an item:
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Matkul item = matkulAdapter.getItem(position);
matkulAdapter.remove(item);
dbReference.removeValue();
matkulAdapter.notifyDataSetChanged();
return true;
}
});
This is my database:
EDIT QUESTION
and also i tried this code with .child but the data only deleted on ListView. So the data comes back when i re-open the ListView.
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Matkul item = matkulAdapter.getItem(position);
matkulAdapter.remove(item);
dbReference.child(item.getNamaMatkul()).removeValue();
matkulAdapter.notifyDataSetChanged();