Cannot retrieve data in ascending order

前端 未结 2 1408
臣服心动
臣服心动 2021-01-27 18:37

I want to retrieve data in ascending order, but received data somehow added to recyclerview in descending order.

Firebase Database:

相关标签:
2条回答
  • 2021-01-27 18:54

    To get a sorted and filtered result, you have to pass a query into the FirebaseRecyclerAdapter constructor:

    public MyFireAdapterDiasFiestaRecyclerView(
        Class<DiaFiestaMeta> modelClass, 
        int modelLayout, 
        Class<MyFireViewHolder> viewHolderClass, 
        Query query) {
        ...
    

    And then invoke it with a query that orders and filters:

    adapter = new MyFireAdapterDiasFiestaRecyclerView(
       DiaFiestaMeta.class,
       layout_that_you_use,
       MyFireViewHolder.class,
       ref.orderByChild("property_to_sort_and_filter_on").equalTo("value_to_filter_on")
    );
    
    0 讨论(0)
  • 2021-01-27 19:15

    Since you can't do that natively with the RTDB, you'll probably want to do something like this:

    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setReverseLayout(true);
    layoutManager.setStackFromEnd(true);
    recyclerView.setLayoutManager(layoutManager);
    

    See https://stackoverflow.com/a/27727398/4548500 for more details.

    0 讨论(0)
提交回复
热议问题