【发布时间】:2019-04-05 03:03:42
【问题描述】:
现在,我的应用使用我在 Firebase 中生成的假玩家显示了一个排行榜,如下所示:
我想知道如何将每个玩我的应用的新玩家的名字添加到排行榜。
现在,我的代码手动接收每个假玩家,我没有自动接收 n 名玩家的方法
user2.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value_temp = dataSnapshot.getValue(String.class);
if(value_temp != null)
workshopParticipants.add(new LeaderPlayers(value_temp));
Collections.sort(workshopParticipants);
//Log.d(TAG, "Value is: " + mHigh);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
//Log.w(TAG, "Failed to read value.", error.toException());
}
});
user3 = database.getReference(Integer.toString(3));
user3.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value_temp = dataSnapshot.getValue(String.class);
Log.d(TAG, value_temp);
if(value_temp != null)
workshopParticipants.add(new LeaderPlayers(value_temp));
Collections.sort(workshopParticipants);
//Log.d(TAG, "Value is: " + mHigh);
for(int a = 0; a < workshopParticipants.size(); a++)
{
players.add(workshopParticipants.get(a).getFullName());
}
for(int a = 0; a < players.size(); a++){
Log.d(TAG, "Players are: " + players.get(a));
}
}
这就是我手动添加假玩家的方式。
它目前适用于假玩家,但如果我有 N 个真实玩家玩我的游戏,那么我希望他们中的所有 N 个也出现在排行榜上。
【问题讨论】:
标签: java android firebase-realtime-database