gpt4 book ai didi

android - 使用不同的键 Firebase Realtime DB 获取值

转载 作者:行者123 更新时间:2023-11-29 01:02:32 25 4
gpt4 key购买 nike

所以我想创建一个 refferal 代码系统,使用 firebase 实时数据库,但我发现了一个困难,我如何才能获得 key refferal 中的所有值?

我已经有了代码,但它只是给我 uid 的值,

显示如下:-

Query query = mDatabase.child(uid).orderByChild("refferal_status");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot movieSnapshot : dataSnapshot.getChildren()) {
UserModel movie = dataSnapshot.getValue(UserModel.class);
if (movie.getRefferal_status().equals("akmKA")) {
Toast.makeText(SpinActivity.this, movie.getRefferal_status(), Toast.LENGTH_SHORT).show();
}
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});

Class Model

 String email;
String point;
String checkin;
String limitation;
String refferal_status;

public UserModel(){

}

public UserModel(String email,String point,String checkin,String limitation,String refferal_status){
this.email = email;
this.point = point;
this.checkin = checkin;
this.limitation = limitation;
this.refferal_status = refferal_status;
}

//setter getter here

所以这是我的数据库 Image

最佳答案

试试这个!

注意:- equals expect String object .

 if ("akmKA".equals(movie.getRefferal_status())) {
Toast.makeText(SpinActivity.this, movie.getRefferal_status(), Toast.LENGTH_SHORT).show();
}

最终代码

Query query = mDatabase.child(uid).orderByChild("refferal_status");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot movieSnapshot : dataSnapshot.getChildren()) {
UserModel movie = dataSnapshot.getValue(UserModel.class);
if ("akmKA".equals(movie.getRefferal_status())) {
Toast.makeText(SpinActivity.this, movie.getRefferal_status(), Toast.LENGTH_SHORT).show();
}
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});

关于android - 使用不同的键 Firebase Realtime DB 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126791/

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