在Firebase Android上更新数据 [英] Updating the data on Firebase Android
问题描述
我想在特定节点上更新Firebase上的日期。
数据库结构:
< a href =https://i.stack.imgur.com/TsYg1.png =nofollow noreferrer>
我试图作为
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());
}
});
$ b我想更新 leftSpace
键值为 newValue
, newValue
是字符串类型。但是它不会更新Firebase中的值。
如果我在这里给出
dataSnapshot.getRef()。child ( leftSpace)的setValue(765)。
它会更新。但是我想在Firebase上以字符串格式进行更新。
我将所有字符串类型的数据保存在Firebase上。 (我的模式类包含所有的类型字符串)
为什么它不更新类型字符串的 newvalue
?
编辑1 建议由@Rjz Satvara
myDB
的新节点作为
不会更新已有的。
Firebase
$ b try {
ref.child(myDb ).child( AWAIS @ gmailcom)子( leftSpace)的setValue( YourDateHere)。
} catch(Exception e){
e.printStackTrace();
}
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.
解决方案 In Firebase To update specific value you can use it...
try {
ref.child("myDb").child("awais@gmailcom").child("leftSpace").setValue("YourDateHere");
} catch (Exception e) {
e.printStackTrace();
}
这篇关于在Firebase Android上更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!