Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating the data on Firebase Android

I want to update the date on Firebase on a specific node.

DB Structure:

enter image description here

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

enter image description here

It is not updating the already one.

like image 991
user6750923 Avatar asked Dec 23 '16 06:12

user6750923


People also ask

How do I update my firestore data on Android?

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.

Which method used to update the Firebase data in Android?

Updating or deleting data To simultaneously write to specific children of a node without overwriting other child nodes, use the updateChildren() method.

Which method is used to update Firebase data?

Using setValue() in this way overwrites data at the specified location, including any child nodes.


1 Answers

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");
like image 163
Rjz Satvara Avatar answered Sep 24 '22 10:09

Rjz Satvara