代码
DatabaseReference = FirebaseDatabase.getInstance().getReference().child("Friends").child(UID);
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("UserData");
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<AllUsersHelper, UsersViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final UsersViewHolder holder, int position, @NonNull AllUsersHelper model) {
holder.setName(model.getName());
holder.setStatus(model.getStatus());
holder.setImage(model.getImage());
final String userId = getRef(position).getKey();
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference().child("UserData").child(userId);
rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
userName = dataSnapshot.child("Name").getValue().toString();
Intent intent = new Intent(getActivity(), Chat.class);
intent.putExtra("Recievers_Id", userId);
intent.putExtra("Recievers_Name", userName);
startActivity(intent);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
当前显示的数据为空,因为定义的数据库引用(mDatabaseReference)中不存在该数据
我要实现的是在“ Friends”子对象内,在“ userid”内,将有多个userids(朋友ID),所以我想获取所有要获取的朋友ID……转到“ UserData”,然后获取所有已经获取的朋友id的数据...有点复杂,所以我不知道该怎么做...有人可以帮帮我吗