我正在Firebase和Android上工作,我想从Firebase数据库中检索有关收据电子邮件的数据,有人可以将我从这种情况中拖出来吗?一些代码或StackOverflow帖子或视频参考也将非常有用,因为它们易于区分。enter image description here
private ListView mlistView;
private ArrayList<String> list;
private ArrayAdapter<String> adapter;
private DatabaseReference ref;
private FirebaseDatabase database;
private RecieptClass fooditem;
private FirebaseAuth auth;
private FirebaseUser user;
private String email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reciept);
final FirebaseUser user = auth.getInstance().getCurrentUser();
email = user.getEmail();
fooditem = new RecieptClass();
mlistView = (ListView)findViewById(R.id.EstlistView);
database = FirebaseDatabase.getInstance();
ref = database.getReference("RecieptData");
list = new ArrayList<>();
adapter = new ArrayAdapter<String>(this,R.layout.reciept_list_item,R.id.ItemRecieptList,list);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
if (email == fooditem.getEmail()) {
fooditem = ds.getValue(RecieptClass.class);
list.add(fooditem.getQuantity() + " " + fooditem.getItemName() + " " + fooditem.getTotalPrice());
mlistView.setAdapter(adapter);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}