Skip to content Skip to sidebar Skip to footer

Updating Firebase Records That Are Displayed In An Android ListView

So far, I have been able to display my Firebase records for node maintenance in an Android ListView. However, there is one part of these records that I wish to update. When clicki

Solution 1:

Can you please try replacing this function with your function and try

Some explanation:

ref.updateChildren(hashMap); // will let you update the only data you want to change

ref.setValue(model);  // will replace the existing data with the model you provided

Function to replace

private boolean updateProgress (String title, String desc, String id, String property, String progress) {
    DatabaseReference databaseReference = FirebaseDatabase.getInstance()
                           .getReference().child("maintenance");
    FirebaseUser user = mAuth.getCurrentUser();
    String uid = user.getUid();

    Map<String, Object> params = new HashMap<>();

    params.put("progress", progress);  // put only params you want to update

    databaseReference.child(uid)
                     .child(id)
                     .updateChildren(params);

    Toast.makeText(this, "Maintenance Updated Updated Successfully", Toast.LENGTH_LONG).show();
    return true;
}

Note: put only params you want to update like in example below, here if you want to change progress only then snippet will be like,

Map<String, Object> params = new HashMap<>();

params.put("progress", progress); 

ref.updateChildren(params);

Post a Comment for "Updating Firebase Records That Are Displayed In An Android ListView"