Display data list in order of date. Firebase

Asked

Viewed 467 times

1

Hello, I’m with a barrier how to bring the data from firebase and display in order by date, display from the latest to the oldest, currently the data are being displayed in standard form in firebase.

database = ConfiguracaoFirebase.getDatabase().child("comentarios");
        //Listener para recuperar os comentarios
    valueEventListenerComentarios = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
                //Limpar lista
            listaComentarios.clear();
                //Listar comentários
            for (DataSnapshot dados: dataSnapshot.getChildren() ){
                Comentario comentario = dados.getValue( Comentario.class );
                listaComentarios.add( comentario );
            }
            arrayAdapter.notifyDataSetChanged();
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    };
  • Child dps, you put .orderBy, Something like that, just type order the rest should already appear, then you put by which field you want to be done to Sort

  • Yes, but I have already made a Query, even so, it does not leave decreasing order.

1 answer

1

After Child you put . orderByChild("")

database = ConfiguracaoFirebase.getDatabase().child("comentarios").orderByChild("Referência_da_data_no_firebase");
  • No, of error, I had tried so.

  • database = Configuracaofirebase.getDatabase(). Child("comments"); query = database.orderByChild("idComentario"); I’m trying to do so, but it doesn’t come in order anyway. p idComentario I’m passing the timestamp, but it doesn’t come in order from the latest to the oldest.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.