我是Firebase数据库中的新手,并且在单击sermoncategory
recycerview时,我试图在android中将这样的数据检索到两个recyclerviews中,显示该数据的所有讲道,有人可以帮助我吗?与Android代码也谢谢!
"sermons"
|_ _"0"
|_ "sermonurl": "https://..."
|_ "sermontitle": "Title"
|_ "sermoncategory": "2"
|_ _"1"
|_ "sermonurl": "https://..."
|_ "sermontitle": "Title"
|_ "sermoncategory": "3"
"sermoncategory"
|
|_ "2"
|_"categorytitle": "Covenant of Blessing"
|_"categoryimageurl": "https://..."
|_"categorydesciption":"bla bla bla"
|_ "3"
|_"categorytitle": "Healing"
|_"categoryimageurl": "https://..."
|_"categorydesciption":"bla bla bla"
答案 0 :(得分:0)
如果您想使用sermoncategory
为2的讲道,则可以使用orderByChild()
这样的查询:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("sermons");
ref.orderByChild("sermoncategory").equalTo(2).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// this dataSnapshot will have all the sermons with sermocategory as 2
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.e("MainActivity", "onCancelled", firebaseError.toException());
}
});