android - Firebase - 检索后单击按钮编辑/更新数据库

标签 android firebase firebase-realtime-database

我在 4 个 Edittexts 和 1 个 Spinner 中从 Firebase 数据库中检索值。

  • 编辑文本 -> fName
  • 编辑文本 -> lName
  • 编辑文本 -> 出生日期
  • 微调器 -> carType
  • 编辑文本 -> 车号

显示所有这些值。但是如何编辑它们并在单击按钮下更新。?

Followed documentation, but no success.

请看这个post .你会明白的

最佳答案

假设您具有与此 question 中相同的数据库结构请使用以下代码:

final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();

yourButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        rootRef.child("Drivers").child(driverId).child("carNumber").setValue("newCarNumber");
    }
});

其中 driverId 是您要更新的特定驱动程序的 ID。 对于其他字段,只需将 carNumber 更改为 cardTypedateOfBirthnamesurname .

例如,如果您想更新最后一个驱动程序的数据,请使用此行:

rootRef.child("Drivers").child("-Kv6q2beyS50VCxxX3M7").child("carNumber").setValue("newCarNumber");

关于android - Firebase - 检索后单击按钮编辑/更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46486704/

相关文章:

android - 设置 recyclerview 中项目的悬停

javascript - 更改所有唯一键中的某些值

ios - 在 iPad3 上而不是在模拟器上运行应用程序时,我在变量上得到 nil。 swift 4

ios - 可以将两个 iOS 应用程序与同一个 Firestore 数据库一起使用吗?

ios - 正确创建 Firebase 引用

android - 在 Firebase 中保存房间数据库文件

android - 房间数据库 : inserted ID is always 0

android - WhatsApp后台运行系统

java - Android Firebase检查子代中是否存在数据

javascript - Undefined 不是一个对象 React Native 和 Firebase