0

I want to order my recyclerview by eventDate but im already using orderByChild. How to do it?

Sorry if i dont explain it well, but on SQL the thing i want to achieve is:

SELECT * FROM Event WHERE eventOrganizer=stringOrganizer ORDER BY eventDate ASC;

This is the code:

    Query query = databaseReferenceEvent.orderByChild("eventOrganizer").equalTo(stringOrganizer);
    FirebaseRecyclerOptions <ModelEvent> options = new FirebaseRecyclerOptions.Builder<ModelEvent>()
        .setQuery(query, snapshot -> new ModelEvent(
            Objects.requireNonNull(snapshot.child("eventID").getValue()).toString(),
            Objects.requireNonNull(snapshot.child("eventOrganizer").getValue()).toString(),
            Objects.requireNonNull(snapshot.child("eventName").getValue()).toString(),
            Objects.requireNonNull(snapshot.child("eventDate").getValue()).toString(),
            Objects.requireNonNull(snapshot.child("eventStatus").getValue()).toString()))
        .build();

    adapter = new FirebaseRecyclerAdapter<ModelEvent, ViewHolderEvent>(options) {
        @NonNull
        @Override
        public ViewHolderEvent onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.list_attendance, parent, false);
            return new ViewHolderEvent(view);
        }
aldi nugraha
  • 105
  • 8

1 Answers1

1

I don't know how is your DB structure, but I think the best is to rethink it. I mean, ordering the nodes from the last, then you query ordering by status