我試圖讓從火力地堡的值。的Android火力地堡檢索值
我用這一段代碼來獲取,但所有的方法,我呼籲score1返回null。
private void onSignedInInitialize(String username) {
mUsername = username;
final DatabaseReference reference = mFirebaseDatabase.getReference();
Query query = reference.child("scores").orderByChild("username").equalTo(mUsername);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post object and use the values to update the UI
Score scores1 = dataSnapshot.getValue(Score.class);
Log.d(TAG, " scores1 " + scores1 + " datasnapshot to String " + dataSnapshot.getValue().toString());
Log.d(TAG, " user " + scores1.getUsername());
Log.d(TAG, " user " + scores1.getUsername());
scoresTextView.setText(scores1.getScore());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
我的火力地堡結構看起來像this
我使用他們的文檔(帶後級)的例子,也搜索在谷歌,但我無法找到我怎麼能得到的分數值。 謝謝你的回答。
這是分數級
public class Score {
private String username;
private String score;
public Score() {
}
public Score(String username, String score) {
this.username = username;
this.score = score;
}
public String getUsername() {
return username;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
}
張揚的變量,然後再試 –
它是相同的,仍空 –
沒有人知道如何獲得價值? –