I have a problem with Firebase database.
When I get data from database, I get old data on the top. How I can change it to get new data on the top?
in firebase console new data also are at the bottom
I'm using listView for 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
}
it void for adding new data in firebase database
//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);
}