[英]How do I create a leaderboard from the stats in my Firebase Realtime Database?
I want to create a leaderboard in my app.我想在我的应用程序中创建一个排行榜。 The leaderboard should show the 10 best users who have the most high scores.
排行榜应显示得分最高的 10 名最佳用户。 My Firebase database looks like this:
我的 Firebase 数据库如下所示:
Firebase Database: Firebase 数据库:
I have already created an activity with 10 TextViews one below the other.我已经创建了一个有 10 个 TextView 的活动,一个在另一个之下。 Starting with the first TextView I want to change the text to:
从第一个 TextView 开始,我想将文本更改为:
"1st place | 'username' | 'highscore' score" “第一名 | '用户名' | '高分' 得分”
Now my question:现在我的问题:
What is the easiest way for me to do this?对我来说最简单的方法是什么?
To get the top 10 users with the highest score, you can use a query like this:要获得得分最高的前 10 位用户,您可以使用如下查询:
DatabaseReference usersRef = FirebaseDatabase.getInstance().getReference("Users");
Query top10Query = usersRef.orderByChild("highscore").limitToLast(10);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.