我希望能够从下图中返回随机对象:
而不仅仅是已经返回的第一个对象(-Kci1vM1dVBYBcPW7QA)。我已经从我的应用程序中插入了当前正在读取的代码。变量1,2和3当前正在读取第一个对象,但我希望它们能够检索随机对象。
public void displayDeals(){
databaseReference.child("FruitDeals").child("bR4sR4flMkYFrw1SzuWA8hpOnY52").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
deals_information = dataSnapshot.getValue(Deals_Information.class);
one = deals_information.getDeal();
two = deals_information.getPrice();
three = deals_information.getAisleNum();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
});
}