我正在 Android 中构建一个消息应用程序,并尝试在 Android 应用程序中从 Firebase 检索数据。但是当我这样做时,我的屏幕上会显示完整的树。我想直接访问 child 。有没有办法只获取我想要的值?
retr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Attach an listener to read the data at our posts reference
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
totalmsg[0] =snapshot.getValue().toString();
emultiview.setText(totalmsg[0].toString());
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
}
});
我想在 Firebase 中检索 hello。我在这里面临的问题是加密数据。我有什么办法可以找回它吗?而且我无法在不使用push()的情况下附加数据,还有push()的其他替代方法吗?
{
"chat" : {
"-JZvOzp0L1ccuBt2TVN7" : {
"author" : "JavaUser21221",
"message" : "hello "
},
"-JZvPneW5et0_EVRvL5g" : {
"author" : "JavaUser21221",
"message" : "hai"
}
}
最佳答案
r.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildKey) {
Map<String,Object> newPost=(Map<String,Object>)snapshot.getValue();
String name1 = String.valueOf(newPost.get("Author"));
String message1 = String.valueOf(newPost.get("Title"));
System.out.println("Message: " + newPost.get("Author"));
System.out.println("Name: " + newPost.get("Title"));
}
});
关于java - 如何在不使用任何加密格式的情况下使用 "PUSH"检索 Firebase 中的子数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26859554/