sisi mendel
sisi mendel

Reputation: 799

Android Firebase Nested Query

I'm using FirebaseListAdapter and trying to get a list of open chat rooms from my Firebase Database, the structure is pretty simple:

Database Structure

This is what I get when I query:

{-KY99IS2mLzayD4HDyd6={location={...}, posts={....} , title="chatname"}

And what I'm trying to achieve is to get the data without the ID part, so it would fit my object builder, something like that:

{location={...}, posts={....} , title="chatname"}

I know that ChildEventListener does that, but I don't have an option to use it with the FirebaseListAdapter, so I hope there's another way to do that.

My code is:

FirebaseListAdapter<ChatRoom> firebaseListAdapter = new FirebaseListAdapter<ChatRoom>(this,ChatRoom.class,R.layout.chatslist_row,myRef3) {
        @Override
        protected void populateView(View v, ChatRoom chatRoom, int position) {
            System.out.println(chatRoom.title);
        }

    };

But it doesn't work because of the key part, it can't use my ChatRoom class object builder.

Thanks!

Upvotes: 1

Views: 873

Answers (1)

You can first get the id (KY99IS2mLzayD4HDyd6) from the child event listener. Then made a new database reference with the id (KY99IS2mLzayD4HDyd6) and call for child event listener again. mDatabase = databaseRef.getReference("chats/KY99IS2mLzayD4HDyd6"); if you call mDatabase now you will get {location={...}, posts={....} , title="chatname"}.

I have solved my issue like that. But not for FirebaseListAdapter. Make your own listview and adapter this might be more flexible.

Upvotes: 1

Related Questions