首先从Firebase实时数据库中检索新项目

时间:2019-02-06 17:32:37

标签: android firebase firebase-realtime-database android-recyclerview recycler-adapter

private void loadOrders(String phone) {

    adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(
            Request.class,
              R.layout.order_layout,
            OrderViewHolder.class,
            requests.orderByChild("phone")
                    .equalTo(phone)

    ) {
        @Override
        protected void populateViewHolder(OrderViewHolder viewHolder, final Request model, final int position) {
            viewHolder.txtOrderId.setText("Order ID: "+adapter.getRef(position).getKey());
            viewHolder.txtOrderStatus.setText("Order Status: "+convertCodeToStatus(model.getStatus()));
            viewHolder.txtOrderAddress.setText("Address: "+model.getAddress());
            viewHolder.txtOrderPhone.setText("Phone Number: "+model.getPhone());
            viewHolder.txtOrderComment.setText("Order Note: "+model.getComment());
            viewHolder.txtOrderDate.setText("Order Date: "+Common.getDate(Long.parseLong(adapter.getRef(position).getKey())));
            viewHolder.btn_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                        alertdialog(position);


                }
            });

            viewHolder.btnDetails.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent orderDetail = new Intent(OrderStatus.this,OrderDetail.class);
                    Common.currentRequest=model;
                    Intent intent = orderDetail.putExtra("OrderId", adapter.getRef(position).getKey());
                    startActivity(orderDetail);


                }
            });

            if((Common.convertCodeToStatus(model.getStatus())).equals("Delivered"))
            {
                viewHolder.btndelivered.setVisibility(View.VISIBLE);

                viewHolder.btn_delete.setVisibility(View.INVISIBLE);
            }



        }
    };
    recyclerView.setAdapter(adapter);
}

这是我用来从数据库中检索订单的代码,但它首先显示了旧订单。如何使它首先检索新订单?

如果我使用(((LinearLayoutManager)layoutManager).setReverseLayout(true);它只是倒置显示列表

enter image description here

0 个答案:

没有答案