姬長信(Redy)

java – 在ListView中显示Firebase数据


好的,所以我让它运行显示用户ID但没有得分.然后我开始做一些改变,忘了我改变了什么,现在我又回到了null null.我觉得我可能删除了一些东西或拼写错误的东西.
   dbref.addValueEventListener(new com.google.firebase.database.ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                ArrayList list = new ArrayList();
                list.clear();

                for(DataSnapshot ds :dataSnapshot.getChildren()) {
                    Score Result = ds.getValue(Score.class);
                    String userId = String.valueOf(Result.getUserId());
                    String score = String.valueOf(Result.getScore());
                    list.add(userId);
                    list.add(score);

                }
                adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, list);
                LvRanking.setAdapter(adapter);
            }

这是我的模特:

public class Score {
private String userId, score;

public Score() {}

public Score(String userId, String score) {
    this.userId = userId;
    this.score = score;
}

public String getUserId() {
    return userId;
}

public String getScore() {
    return score;
}

@Override
public String toString() {
    return "Score{" +
            "userId='" + userId + '/'' +
            ", score='" + score + '/'' +
            '}';
}
 }

数据库:
Link to my database screenshot