gpt4 book ai didi

java - 如何从 firebase/Android 检索子级的数据子级

转载 作者:行者123 更新时间:2023-12-02 10:31:49 27 4
gpt4 key购买 nike

Here is my firebase database

Here is the info.class

Here is the insert

我想将所有数据从 firebase 获取到 ListView

如何获取“信息”数据列表下的所有数据?请帮忙

db = FirebaseDatabase.getInstance();
ref = db.getReference("infomation");

protected void onStart() {
super.onStart();

ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
infoList.clear();
for (DataSnapshot infoSnapshot : dataSnapshot.getChildren()){

info info = infoSnapshot.getValue(info.class);
infoList.add(info);

}
InfoList adapter = new InfoList(Welcome.this, infoList);
listViewInfo.setAdapter(adapter);

}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}

最佳答案

在您的插入部分,您需要将其更改如下,

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("information");
ref.child( FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(in);

但是如果你想保存数据,就像保存数据一样

information >uid> random value > then the data

使用如下所示的更改数据检索部分

 for (DataSnapshot infoSnapshot : dataSnapshot.getChildren().getChildren()){

info info = infoSnapshot.getValue(info.class);
infoList.add(info);

}

关于java - 如何从 firebase/Android 检索子级的数据子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53578965/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com