我的Firebase數據庫出現問題。先用Firebase數據庫顯示新條目
當我從數據庫中獲取數據時,我會在頂部獲取舊數據。我如何改變它以在頂部獲取新數據?
in firebase console new data also are at the bottom
我使用的ListView的FirebaseAdapter。
// setting adapter
private void showAdapter() {
fBListAdapter = new FirebaseListAdapter<DiscountProduct>(ListDiscountActivity.this, DiscountProduct.class, R.layout.model_of_product, refDiscount) {
@Override
protected void populateView(View v, DiscountProduct model, int position) {
TextView nameProduct;
nameProduct = (TextView) .findViewById(R.id.modelCardNameProduct);
nameProduct.setText(model.getNameProduct());
}
};
listofDiscountProducts.setAdapter(fBListAdapter); //It's ListView on Activity
}
它喪失了在火力數據庫添加新的數據
//adding data to firebase database
public static void createNewDiscountPost(String nameProduct) {
String key = refDiscount.push().getKey();
DiscountPost discountPost = new DiscountPost(nameProduct);
Map<String, Object> createNewDiscountPost = discountPost.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/" + key, createNewDiscountPost);
refDiscount.updateChildren(childUpdates);
}
另見http://stackoverflow.com/questions/34156996/firebase-data-desc-sorting-in-android –
取得與推IDS的最新記錄在一個查詢中(因爲一些來到這個線程將試圖做)使用'limitToLast(n)',它會給你從列表的末尾的項目。 – Kato