Abhinav Chauhan
Abhinav Chauhan

Reputation: 1384

How to query this data from firebase and set to FirebaseRecyclerOptions

This is the structure of my data at firebase Realtime database

So there are members and all of them submits fee at monthly basis so I created separate reference for their fee records to make structure more flat.

under the "fee" the top level keys are the keys of member to which the records belong, so that i can query records for specific memebers and then inside it there are fee records which have their own key, so how do i query only the fee records.

because it want to pull the only fees data in a FirebaseRecyclerAdaper what i have done so far is.

 Query baseQuery = FireBaseHandler.getInstance(getActivity()).getFeeReference();
    FirebaseRecyclerOptions<FeeRecord> options = new FirebaseRecyclerOptions.Builder<FeeRecord>()
            .setLifecycleOwner(this)
            .setQuery(baseQuery,FeeRecord.class)
            .build();

    mAdapter = new FirebaseRecyclerAdapter<FeeRecord,Holder>(options) {

        @Override
        protected void onBindViewHolder(@NonNull final Holder holder, int i, @NonNull FeeRecord feeRecord) {

        }
        @NonNull
        @Override
        public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            LayoutInflater inflater = LayoutInflater.from(getActivity());
            return new Holder(inflater,parent);
        }

But the baseQuery here only return everything under fee and send them to recycler adapter but it is returning only two children , which you can see why in the structure above . How do i get feeRecords inside these two children and lay them in the recycler view.

Or do you recommend changing the structure

Thanks in advanace

Upvotes: 0

Views: 386

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

The adapter in FirebaseUI are made to display a single flat list of data from the Realtime Database. So in your data model, they can either display the list of users (the nodes directly under /fees), or the fees for one specific user (the nodes under one /fees/$pushid).

The FirebaseUI adapters cannot display all nodes in a tree, or at least not without significant modification on your part.

I recommend:

Upvotes: 1

Related Questions