java - 是否可以在 firebase 上仅更新我 child 的特定数据?

标签 java android firebase firebase-realtime-database

是否可以仅更新我的 Android Firebase 上的特定用户的数据?我该怎么做?例如,如果我使用管理员帐户,我可以在哪里专门更新所有用户?

例如在我的 firebase 数据库上 enter image description here

我只想更新 SCYQ 的用户详细信息 --- 我想更改姓名、电子邮件、日期。只保留该用户的信息而不影响其他用户的信息?

最佳答案

是的,这是可能的:

FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
String useruid=user.getUid();
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Accounts").child("user").child(useruid);
ref.child("date").setValue(newdate);
ref.child("email").setValue(newemail);
ref.child("name").setValue(newname);
ref.child("type").setValue(newtype);

如果您在 ListView 中有名称列表并且想要更新它们,则可以执行以下操作:

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final String selectedFromList = (String) listview.getItemAtPosition(position);
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Accounts").child("user").child(useruid);
ref.orderByChild("name").equalTo(selectedFromList).addValueEventListener(new ValueEventListener(){
 @Override
 public void onDataChange(DataSnapshot dataSnapshot) {

  //update values here
     }
  }

   @Override
 public void onCancelled(FirebaseError firebaseError) {

            }
        });
    });

关于java - 是否可以在 firebase 上仅更新我 child 的特定数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48904039/

相关文章:

android - 在 Android 中使用 Google map v2

android - FCM 默认图标使用无效渐变

ios - 在我的 iOS 应用程序中实现 pod 'Firebase/Firestore' 后无法运行应用程序

java - 我可以在java中为Android应用程序xml布局添加if else 'setContentView'吗?

java - 无法为 JTable 提供首选大小

java - 保存卡在适配器中的位置

java - 境界有新变化?

java - 非常基本的 GObject/GOval For 循环

Java事件: Is this a good way to go about it?

android - "GoogleApiClient is not connected yet"在使用 Firebase 身份验证和谷歌登录时注销