我想查询orderByValue它总是返回null 但是当我正常删除.orderByValue数据时。请帮忙
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("newfeed").child(FirebaseRef.mAuth.getCurrentUser().getUid()).orderByValue().limitToFirst(10).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
for (DataSnapshot data : dataSnapshot.getChildren()) {
lastRating = data.getValue(Double.class);
loadData(data.getKey());
Log.d("Key ", data.getKey());
}
}
else{
mProgressBar.setVisibility(RecyclerView.GONE);
mProgressBarTop.setVisibility(RecyclerView.GONE);
}
}
@Override public void onCancelled(DatabaseError databaseError) {
mProgressBar.setVisibility(RecyclerView.GONE);
}
});
}
以下是我的JSON示例。
"newfeed" : {
"7gE2qiqoblSHDHubiEW0IzrhzIQ2" : {
"-Kn090eIxMH338xIwA8J" : 69259.23018812927,
"-Kn092jf25h2Qdmk--RX" : 69268.71984827428,
"-Kn093LPOBCCE1-Ygx6t" : 69270.82899176712,
"-Kn093P2PE2rIml4XyKI" : 121518.05765189118,
"-Kn09lD0cGUhRQPbvJtS" : 69394.93008559482,
"-Kn0BYI-7IQzkCmBH8gN" : 69892.8262113143,
"-Kn4UkNCe1rhpiJ_Rrew" : 3133576.6418433865
}
答案 0 :(得分:0)
我不确定你会得到什么,这就是我自己运行此代码的原因:
ref.orderByValue().limitToFirst(10).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
Log.d("Key ", data.getKey()+": "+data.getValue());
}
}
@Override public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
});
打印:
D / Key:-Kn090eIxMH338xIwA8J:69259.23018812927
D / Key:-Kn092jf25h2Qdmk - RX:69268.71984827428
D / Key:-Kn093LPOBCCE1-Ygx6t:69270.82899176712
D / Key:-Kn09lD0cGUhRQPbvJtS:69394.93008559482
D / Key:-Kn0BYI-7IQzkCmBH8gN:69892.8262113143
D / Key:-Kn093P2PE2rIml4XyKI:121518.05765189118
D / Key:-Kn4UkNCe1rhpiJ_Rrew:3133576.6418433865
从快速扫描看起来对我来说是正确的顺序。