我正在尝试从firebase数据库中检索一些数据并将其填充到recyclerview。查询背后的逻辑是将具有异性的用户显示为当前用户但是同一个大厅。例如,如果当前用户是“男孩”并且在“Legon”大厅中,则在数据库中的legon hall中使用“女性”填充回收者视图。
用户数据库:
这是我想要做的但是没有用
@Override
protected void onStart() {
super.onStart();
final String user_id = firebaseAuth.getCurrentUser().getUid();
final User user = new User();
final String halls = user.getHalls();
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
if(dataSnapshot.child("Male").hasChild(user_id)){
query = databaseReference.child("Female").orderByChild("halls").equalTo(halls);
}
else{
query = databaseReference.child("Male").orderByChild("halls").equalTo(halls);
}
}
@Override
public void onCancelled(DatabaseError databaseError){
}
});
FirebaseRecyclerAdapter<User, UserViewholder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<User, UserViewholder>(
User.class,
R.layout.users_row,
UserViewholder.class,
query
) {
@Override
protected void populateViewHolder(UserViewholder viewHolder, User model, int position) {
viewHolder.setUsername(model.getUsername());
viewHolder.setLevels(model.getLevels());
viewHolder.setDownloadUrl(getApplicationContext(), model.getDownloadUrl());
}
};
users2.setAdapter(firebaseRecyclerAdapter);
}
答案 0 :(得分:0)
我认为你错了
final User user = new User();
final String halls = user.getHalls();
因为halls
总是返回null
您应该将其更改为
User user = firebaseAuth.getCurrentUser();
final String halls = user.getHalls();