现在我正在尝试将数据检索为:
FirebaseDatabase.getInstance().getReference().child("Users").child(userUid).addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get values for user.fullname and user.coursename
if (!(dataSnapshot == null)) {
Users user = dataSnapshot.getValue(Users.class);
fullName = user.FullName;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
但这不起作用,在调试Ondatachange永远不会执行时,变量fullName始终保持为null。大多数其他firebase检索都会发生同样的情况,尽管对recycleradapter的查询就像魅力一样。
以下是我的用户类:
public class Users {
public String FullName;
public String CourseName;
public Users(){
// Default constructor required for calls to DataSnapshot.getValue(Post.class)
}
@Exclude
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("FullName",FullName);
result.put("CourseName",CourseName);
return result;
}
}