我想从firebase中获取所有数据,也想将该数据存储到firebase recyclerview中。该代码仅显示了进入回收站视图的最后一个条目。但是当我从Firebase删除最后一个数据时,它将显示倒数第二个数据。或如何将子字段添加到Firebase recyclerview。
mDatabase.addValueEventListener(new ValueEventListener() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot datas : dataSnapshot.getChildren()) {
keys = datas.getKey();
date = datas.child("date").getValue().toString();
IsCompleted = datas.child("isCompleted").getValue().toString();
MobileNoFB = datas.child("mobileNo").getValue().toString();
//Toast.makeText(YourOrdered.this, "Date is :- " + date + " IsCompleted:- " + IsCompleted, Toast.LENGTH_LONG).show();
if (MobileNoFB.matches(MobileNumber)) {
moDatabase = FirebaseDatabase.getInstance().getReference().child("Pending_Orders").child(keys).child("Orders");
// Recyclerview data
final FirebaseRecyclerAdapter<YourOrderAdapter, YourOrderViewHolder> YORecyclerView = new FirebaseRecyclerAdapter<YourOrderAdapter, YourOrderViewHolder>
(YourOrderAdapter.class, R.layout.client_order, YourOrderViewHolder.class, moDatabase) {
@Override
protected void populateViewHolder(final YourOrderViewHolder viewHolder, final YourOrderAdapter model, final int position) {
viewHolder.setProImage(getApplicationContext(), model.getProductImage());
viewHolder.setProductQuantity(model.getProductQuantity());
viewHolder.setDate(date);
viewHolder.setIsCompleted(IsCompleted);
viewHolder.setProductColor(model.getProductColor());
viewHolder.setProductNo(model.getProductNo());
}
};
YORecyclerView.notifyDataSetChanged();
mBlogList.setAdapter(YORecyclerView);
} else {
Toast.makeText(YourOrdered.this, "Ordered does not found...", Toast.LENGTH_LONG).show();
}
//Toast.makeText(YourOrdered.this, "I is:- " + i, Toast.LENGTH_LONG).show();
}
//Toast.makeText(YourOrdered.this, "Date is :- " + date + " IsCompleted:- " + IsCompleted,Toast.LENGTH_LONG).show();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 0 :(得分:0)
请删除
`mBlogList.setAdapter(YORecyclerView);`
从for循环添加到for循环之后
`mBlogList.setAdapter(YORecyclerView);`