Sort A Firebaserecycleradapter
I'm making an app that shows the days of the week coming from FireBase, the problem is that I have them messed up and I want them to be sorted. I have searched in many places and p
Solution 1:
The reason only one item shows up is that you only call bindViewHolder
conditionally:
if (this.getItemCount() == position + 1) {
viewHolder.bindDatos(dias);
}
Remove that condition and the others will show up too.
To get a sorted and filtered result, you have to pass a query into the FirebaseRecyclerAdapter
constructor, where you are now passing in a DatabaseReference
. So add a constructor to your adapter that takes a Query
:
publicMyFireAdapterDiasFiestaRecyclerView(
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")
);
Solution 2:
I've done what you told me. For this I have included in my FireBase Database a field called "order". This field will be in which the nodes will be sorted:
{
"descripcion" : "desc1",
"diasFiestas" : {
"Domingo5deMarzo2017" : {
"orden" : 4,
"tituloDiaFiesta" : "Domingo 5 de Marzo",
"uidDiaFiesta" : "Domingo5deMarzo2017"
},
"Jueves2deMarzo2017" : {
"orden" : 1,
"tituloDiaFiesta" : "Jueves 2 de Marzo",
"uidDiaFiesta" : "Jueves2deMarzo2017"
},
"Jueves9deMarzo2017" : {
"orden" : 8,
"tituloDiaFiesta" : "Jueves 9 de Marzo",
"uidDiaFiesta" : "Jueves9deMarzo2017"
},
"Lunes6deMarzo2017" : {
"orden" : 5,
"tituloDiaFiesta" : "Lunes 6 de Marzo",
"uidDiaFiesta" : "Lunes6deMarzo2017"
},
In my Fragment:
adaptadorDiasFiestas = newMyFireAdapterDiasFiestaRecyclerView(DiaFiestaMeta.class, R.layout.fila_diasfiesta_layout, MyFireAdapterDiasFiestaRecyclerView.MyFireViewHolder.class, mDataBaseDiasFiestaSelRef.orderByChild("orden"));
But it does not order anything
Post a Comment for "Sort A Firebaserecycleradapter"