当用户下订单时,会在firebase上自动创建表请求,并在该表中包含名称,电话号码,地址。现在在另一个活动中,我想查看已下达的订单,并希望在回收站视图中检索数据,但应用程序显示空白屏幕。这是我的java代码。
public class OrderStatus extends AppCompatActivity {
public RecyclerView recyclerView;
public RecyclerView.LayoutManager layoutManager;
FirebaseRecyclerAdapter<Request,OrderViewHolder> adapter;
FirebaseDatabase database;
DatabaseReference requests;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_status);
//firebase
database=FirebaseDatabase.getInstance();
requests=database.getReference("Requests");
recyclerView= (RecyclerView)findViewById(R.id.listOrders);
recyclerView.setHasFixedSize(true);
layoutManager= new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
loadOrders();
}
private void loadOrders() {
adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(
Request.class,
R.layout.order_layout,
OrderViewHolder.class,
requests.orderByChild("phone")
.equalTo("phone")
) {
@Override
protected void populateViewHolder(OrderViewHolder viewHolder, Request model, int position) {
viewHolder.txtOrderId.setText(adapter.getRef(position).getKey());
viewHolder.txtOrderStatus.setText(convertCodeToStatus(model.getStatus()));
viewHolder.txtOrderAddress.setText(model.getAddress());
viewHolder.txtOrderPhone.setText(model.getPhone());
}
};
recyclerView.setAdapter(adapter);
}
private String convertCodeToStatus(String status) {
if (status.equals("0"))
return "placed";
else if (status.equals("1"))
return "On my way";
else
return "Shipped";
}
}
答案 0 :(得分:0)
您没有在方法加载订单中传递参数,因此您尝试这样做对我有用 private void loadOrders(){
adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(
Request.class,
R.layout.order_layout,
OrderViewHolder.class,
requests.orderByChild("phone")
)