1
不工作在我的Android應用我使用下面的代碼OrderByChild()在Android客戶端
FirebaseDatabase database = FirebaseDatabase.getInstance();
ref = database.getReference().child(Keys.CONTACTIFY_CONTACTS).child(sharedPrefs.getString(SharedPreferenceValues.CURRENT_USER_UID, "")).child(Keys.SHARED_CONTACTS);
refer = ref.orderByChild(Keys.TIME);
refer.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ArrayList<HashMap<String, Object>> sharedList = new ArrayList<HashMap<String, Object>>();
if (dataSnapshot.getValue() != null) {
Object[] rootData = ((HashMap<String, Object>) dataSnapshot.getValue()).values().toArray();
for (Object singleElement :
rootData) {
HashMap<String, Object> eachElement = (HashMap<String, Object>) singleElement;
sharedList.add(eachElement);
}
recyclerView.setAdapter(new SharedItemsRecyclerViewAdapter(sharedList, mListener, getActivity()));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
我的火力數據庫結構
我的火力地堡規則相關的情況是
{
"rules": {
"mapper":{
".read": "auth!= null",
".write": "auth!= null"
},
"share_id_mapper":{
".read": "auth!= null",
".write": "auth!= null"
},
"contactify_contacts":{
//can read a message if authenticated
"$uid": {
"shared_contacts": {".indexOn": "time",
".write": "auth!= null",
問題是我得到了hasmap從默認的排序方式,即sortbyKey()快照。但我期待基於節點數據中時間鍵值的結果。
雖然有效,但是 List data = new ArrayList (); 是有點混淆,但休息是好的;-)。 –
如何顛倒默認順序,如上升或下降? –
https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#reverse(java.util.List) –