当我从Request的节点使用Firebase回收适配器时,我想从Client的节点读取子节点的名称(值),其中子节点具有Client密钥的值
我尝试过,但是我只收到链接
adapter=new FirebaseRecyclerAdapter<Request, OrderViewHolder>(optionsReq) {
@Override
protected void onBindViewHolder(@NonNull OrderViewHolder holder, final int position, @NonNull final Request model) {
holder.txtOrderId.setText(adapter.getRef(position).getKey());
holder.txtOrderStatus.setText(Common.convertCodeToStatus(model.getStatus()));
holder.txtOrderAddress.setText(model.getAddress());
holder.txtOrderDate.setText(Common.getDate(Long.parseLong(model.getDate())));
holder.txtOrderClient.setText(client.child(model.getDniclient()).child("name").toString());
@NonNull
@Override
public OrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_layout, parent,false);
return new OrderViewHolder(view);
}
};
recyclerView.setAdapter(adapter);
}
答案 0 :(得分:0)
DatabaseReference databaseReference;
String name;
adapter=new FirebaseRecyclerAdapter<Request, OrderViewHolder>(optionsReq) {
@Override
protected void onBindViewHolder(@NonNull OrderViewHolder holder, final int position, @NonNull final Request model) {
holder.txtOrderId.setText(adapter.getRef(position).getKey());
holder.txtOrderStatus.setText(Common.convertCodeToStatus(model.getStatus()));
holder.txtOrderAddress.setText(model.getAddress());
holder.txtOrderDate.setText(Common.getDate(Long.parseLong(model.getDate())));
holder.txtOrderClient.setText(client.child(model.getDniclient()).child("name").toString());
databaseReference = FirebaseDatabase.getInstance().getReference().child("Client").child(model.getDniclient());
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
name = dataSnapshot.child("name").getValue().toString();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
@NonNull
@Override
public OrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_layout, parent,false);
return new OrderViewHolder(view);
}
};
recyclerView.setAdapter(adapter);
}