You are on the right track in your example, you just need to extract the information once it is loaded. It is fairly confusing to get it working but I will point you to this answer of mine, which shows how to do it for achievements - doing it for leaderboards works the same way, except that you will use the leaderboard interfaces instead of those used for achievements.
Basically, you will access arg2
to get the data, and it should look something like this:
mGamesClint.loadTopScores(new OnLeaderboardScoresLoadedListener() {
public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1, LeaderboardScoreBuffer arg2) {
// iterate through the list of returned scores for the leaderboard
int size = arg2.getCount();
for ( int i = 0; i < size; i++ ) {
LeaderboardScore lbs = arg2.get( i );
// access the leaderboard data
int rank = i + 1; // Rank/Position (#1..#2...#n)
String name = lbs.getScoreHolderDisplayName();
String scoreStr = lbs.getDisplayScore();
long score = lbs.getRawScore();
// now display or cache these values, or do whatever with them :)
}
arg2.close();
arg1.close();
}
}, LEADERBOARD_ID,LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 5, true);
I did not actually test this implementation, but it should work (or at least show you enough so you can fix any mistakes I might have made).
Just remember that this will be done asynchronously, so the contents of the method will not execute immediately, but rather once the scores have been loaded.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…