DatabaseReference nume_sofer = database.getReference("Rute").child("1").child("Sofer");
nume_sofer.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String sofer_nume = dataSnapshot.getValue(String.class);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
assert user != null;
if(Objects.equals(user.getDisplayName(), sofer_nume)) {
答案 0 :(得分:1)
您可以在侦听器范围之外声明它,然后在其内部初始化它,以便可以在if语句中使用它
编辑:选中此项
DatabaseReference nume_sofer = database.getReference("Rute").child("1").child("Sofer");
String sofer_nume = null;
nume_sofer.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
sofer_nume = dataSnapshot.getValue(String.class);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
assert user != null;
if(Objects.equals(user.getDisplayName(), sofer_nume)) {