Get key for items with FirebaseRecyclerViewAdapter?

1,700 views
Skip to first unread message

Justin Ricks

unread,
May 10, 2016, 6:20:57 PM5/10/16
to Firebase Google Group
Hi all,

I am accessing data structured like this:


    "UID": {
        "Groceries": {
            "amount": 25000
            , "refreshCode": 0
            , "lastRefresh": "YYYY-MM-DD"
            , "balance": 2695
        }
        , "Gas": {
            "amount": 4343
            , "refreshCode": 1
            , "lastRefresh": "YYYY-MM-DD"
            , "balance": -23
    }

And I would like to put it into a RecyclerView with FirebaseUI. One of the pieces of information that I need to display when I bind my ViewHolder is the key (in this case "Groceries" or "Gas". If I take my Firebase reference up to include UID, how would I access the names of the keys? Or do I need to store them as a separate value in each entry?

Also, is there a place to go for documentation on FirebaseUI for Android? That would be very useful for me.

Thanks!

-Justin

Frank van Puffelen

unread,
May 10, 2016, 6:24:15 PM5/10/16
to Firebase Google Group
In your populateViewHolder() method you get a int position parameter. 
With that you can look up the reference to the item: Firebase ref = adapter.getRef(position);
And then from that you can get the key: ref.getKey();

Justin Ricks

unread,
May 10, 2016, 6:34:41 PM5/10/16
to Firebase Google Group
And ref.getKey(); returns a string? Is there someplace that I can find documentation on how all this works? The GitHub readme only gets me so far.

Thanks lots!

Frank van Puffelen

unread,
May 10, 2016, 6:37:47 PM5/10/16
to Firebase Google Group
getRef() returns a Firebase reference. Since that is not specific to FirebaseUI, it is documented in the regular Firebase documentation: https://www.firebase.com/docs/android/api/#firebase_methods

I highly recommend reading the Firebase guide for Android developers, which is a good introduction to "all things Firebase+Android".

Justin Ricks

unread,
May 10, 2016, 7:22:11 PM5/10/16
to Firebase Google Group
Thanks, that's very helpful!

Oyeleke Okiki

unread,
Nov 16, 2016, 8:09:24 AM11/16/16
to Firebase Google Group

Hi @Frank van Puffelen . Even months after, this was very helpful, thank you so much!
Reply all
Reply to author
Forward
0 new messages