I want to update the date on Firebase on a specific node.
DB Structure:
I am trying as
private void updateData() {
database = FirebaseDatabase.getInstance();
myref = database.getReference();
myref.child("myDb").child("awais@gmailcom").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.getRef().child("leftSpace").setValue(newValue);
dialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d("User", databaseError.getMessage());
}
});
}
I want to update the leftSpace
key with the value of newValue
, newValue
is the type of string here. But it is not updating the value in Firebase.
If I give here
dataSnapshot.getRef().child("leftSpace").setValue(765);
it updates well. But I want to update in the format of string on the Firebase.
I saved the data on Firebase of all string types. (My pattern class contains all of the type strings)
Why it is not updating the newvalue
of type string here?
Edit 1 Suggested by @Rjz Satvara
You method is adding a new node under myDB
as
It is not updating the already one.
Step 1: Creating a new Activity for updating the data For creating a new Activity navigate to the app > res > layout > Right-Click on it and click on New > then click on Empty Activity to create a new Activity and we will name it as UpdateCourse.
Updating or deleting data To simultaneously write to specific children of a node without overwriting other child nodes, use the updateChildren() method.
Using setValue() in this way overwrites data at the specified location, including any child nodes.
In Firebase To update specific value you can use it...
ref.child("myDb").child("awais@gmailcom").child("leftSpace").setValue("YourDateHere");
or you can move into child using "/" as follow :
ref.child("myDb/awais@gmailcom/leftSpace").setValue("YourDateHere");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With