从特定节点的Firebase数据库中检索数据

问题描述:

我正在开发一个android应用程序,现在我只能从特定的节点中检索数据,就像我只想从每个节点中检索一个值一样.数据库结构如下所示.

I am developing an android application and now I am stuck in retrieving data from particular nodes like I want to retrieve only one value from each nodes. The database structure shows below.

如何检索由Firebase数据库创建的第二个唯一ID?

How can I retrieve the second unique id that created by Firebase database?

首先创建一个POJO类以获取所需的值,它的编写方式应与在Firebase中获取它们的方式相同.

First create a POJO class to get the values you want, it should be writen the same way as you have them in Firebase.

public class AppointmentsPojo {

    private String appointmentStuts;

    public AppointmentsPojo(){

    }


    public String getAppointmentStuts() {
        return appointmentStuts;
    }

    public void setAppointmentStuts(String appointmentStuts) {
        this.appointmentStuts = appointmentStuts;
    }

}

然后只需在约会内部循环以获取每个 appointmentStuts

Then just loop inside Appointments to get each appointmentStuts

mDatabase.child("Appointments").addListenerForSingleValueEvent(new ValueEventListener() {
  @Override
  public void onDataChange(DataSnapshot dataSnapshot) {
    //Looping inside Appointments to get each appointmentsStuts
    for(DataSnapshot snapshot: dataSnapshot.getChildren()){
    AppointmentsPojo ap = snapshot.getValue(AppointmentsPojo.class);
    //Getting each appointmentStuts
     String appointmentStuts = ap.getAppointmentStuts();
     //To get each father of those appointments 
     String key = snapshot.getKey();

      Log.e("Data: " , "" + appointmentStuts );

       }

  }

  @Override
  public void onCancelled(DatabaseError databaseError) {
    System.out.println("The read failed: " + databaseError.getCode());
  }
});

mDatabase在哪里

Where mDatabase is

DatabaseReference mDatabase;

mDatabase = FirebaseDatabase.getInstance().getReference();