Android 查询子系统上的密钥
我是firebase的新手,希望获得在类别键中包含特定键的所有存储记录,如何从上面的数据中检索结果,其中category=category_09 我的数据库:Android 查询子系统上的密钥,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我是firebase的新手,希望获得在类别键中包含特定键的所有存储记录,如何从上面的数据中检索结果,其中category=category_09 我的数据库: { "Shops" : { "shop_01" : { "adress" : "Calle Belisario Domínguez 3,", "category" : "category_08", "description" : "One Description", "email
{
"Shops" : {
"shop_01" : {
"adress" : "Calle Belisario Domínguez 3,",
"category" : "category_08",
"description" : "One Description",
"email" : "luiggis@gmail.com",
"facebook" : "www.facebook.com/profile",
"horary" : "8 am - 10pm",
"image" : "https://firebasestorage.googleapis.com/v0/b/...",
"latitude" : 19.561588,
"longitude" : -97.240889,
"name" : "Grupo Culinario Luiggi's",
"phone" : 28128253532
}
},"shop_02" : {
"adress" : "Rafael Murillo Vidal",
"category" : "category_09",
"description" : "One description",
"email" : "lp@gmail.com",
"facebook" : "www.facebook.com/profile",
"horary" : "8 am - 10pm",
"image" : "https://firebasestorage.googleapis.com/v0/b/...",
"latitude" : 19.561588,
"longitude" : -97.240889,
"name" : "Grupo Culinario Luiggi's",
"phone" : 232321532
}
}
我希望能得到您的帮助,非常感谢您每次查看分类,都能解决问题
public class Main_Activity extends AppCompatActivity {
private DatabaseReference mList;
private FirebaseDatabase mFirebaseInstance;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFirebaseInstance = FirebaseDatabase.getInstance();
mList = mFirebaseInstance.getReference("Shops");
mList.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
if(child.child("category").getValue().toString().equals("category_09"){
String adress = child.child("adress").getValue().toString();
String facebook = child.child("facebook").getValue().toString();
String latitude = child.child("latitude").getValue().toString();
String name = child.child("name").getValue().toString();
String longitude = child.child("longitude").getValue().toString();
//then just add them to a list or db
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
我假设Shops是您的Shops表的参考谢谢,这正是我需要的
DatabaseReference database = FirebaseDatabase.getInstance().getReference("shops");
Query category = database.orderByChild("category").equalTo(CATEGORY_09);
category.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// get the data here of CATEGORY_09
}
...
}