尝试通过orderByChild()通过电话订购,但无法正常工作?

时间:2018-11-18 17:51:58

标签: java android firebase firebase-realtime-database

enter image description here

我不知道为什么,但是orderByChild()是Firebase数据库。

loadOrders(Common.currentUser.getPhone());
}

 private void loadOrders(final String phone) {

   FirebaseRecyclerOptions<Request> options;
   options = new FirebaseRecyclerOptions.Builder<Request>()
           .setQuery(requests, Request.class)
           .build();
   Log.e(TAG, "after options");


   adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(options) {
       @Override
       protected void onBindViewHolder(@NonNull OrderViewHolder holder, int position, @NonNull Request model) {
           requests.orderByValue().equalTo(phone);
           holder.txtOrderId.setText(adapter.getRef(position).getKey());
           holder.txtOrderStatus.setText(convertCodeToStatus(model.getStatus()));
           holder.txtOrderAddress.setText(model.getAddress());
           holder.txtOrderPhone.setText(model.getPhone());
           final Request clickItem = model;
       }

       @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);
   adapter.startListening();
   adapter.notifyDataSetChanged();

}

我在这里尝试通过电话订购请求,但数据未订购,它显示了所有请求,我该怎么办?

1 个答案:

答案 0 :(得分:0)

听起来您正在寻找:

FirebaseRecyclerOptions<Request> options;
options = new FirebaseRecyclerOptions.Builder<Request>()
       .setQuery(requests.orderByChild("phone"), Request.class)
       .build();

您还将要删除requests.orderByValue().equalTo(phone),这在这里是毫无意义的声明。