Creating a leaderboard - Using orderbyvalue() in Android

736 views
Skip to first unread message

Eduardo Shinkawa

unread,
Jun 5, 2015, 8:14:08 PM6/5/15
to fireba...@googlegroups.com

Hey guys,

just want ideas about how to create a leaderboard in Android. 

I structured the tree like the example on:


{
  "scores": {
    "bruhathkayosaurus" : 55,
    "lambeosaurus" : 21,
    "linhenykus" : 80,
    "pterodactyl" : 93,
    "stegosaurus" : 5,
    "triceratops" : 22
  }
}

But the example doesn't suggest how to put this on an activity. Should I put this on a listview? Any other simpler way?

Thanks in advance

Frank van Puffelen

unread,
Jun 5, 2015, 9:20:32 PM6/5/15
to fireba...@googlegroups.com
Hi Eduardo,

Our documentation are indeed "a bit" lacking in that respect. The best you can probably do today is look at some of our example apps. The simplest one that maps nodes from Firebase to a list view is our AndroidChat sample.

There are three important parts in this application that work together to map Firebase nodes to a list view:
  1. Chat.java
    This is a simple POJO that defines the fields that are stored for a chat message in Firebase. When you read/write values to Firebase, it will map the fields from the POJO to corresponding properties in the JSON structure.
  2. FirebaseListAdapter.java
    This generic class adapts the collection structure that Firebase uses, to one that Android wants to back a ListView. It handles all the heavy-lifting of mapping Firebase's child_* events to an ArrayList.
  3. ChatListAdapter.java
    This is a subclass of FirebaseListAdapter and it translates the abstract behavior into a concrete implementation of what we need for our chat application. Most important is its populateView method, which you have to implement to map the fields from our Chat object to the View objects.
We'll definitely be working to improve our documentation in this area. But hopefully the above description and the AndroidChat application itself are enough to get you started. If not, just reach out and I'll be happy to explain more.

      Frank

Eduardo Shinkawa

unread,
Jun 6, 2015, 11:06:57 PM6/6/15
to fireba...@googlegroups.com
I will give it a try Frank, thank you!
Reply all
Reply to author
Forward
0 new messages