0

I'm a newbie in firebase database and I'm trying to retrieve data like this in android into two recyclerviews when on click on sermoncategory recycerview show all the sermons of that data can anyone help me with this? with android code also thanks!!

"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"
PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20
  • 1
    Can you kindly be more precise? What data do you want to retrieve from the database? – PradyumanDixit Oct 15 '18 at 08:19
  • I want to link both nodes just like SQL database keys as the firebase database is not relational so...like get all movie categories genres(comedy, drama, action..etc) in one recycerview and when onclick link it to the specified data by their id – Vãmsi Madduluri Oct 15 '18 at 08:20
  • From what I'm getting you want to first know the category of your sermon and if suppose that category is 2, you want to display the data of sermoncategory with node 2, right? – PradyumanDixit Oct 15 '18 at 08:22
  • **[This](https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter/49384849)** is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a `RecyclerView` using `FirebaseRecyclerAdapter`. – Alex Mamo Oct 15 '18 at 08:23
  • @PradyumanDixit yes!! – Vãmsi Madduluri Oct 15 '18 at 08:27
  • thanks, @AlexMamo for helping me out about the recycleview adapter. – Vãmsi Madduluri Oct 15 '18 at 08:32
  • @VãmsiMadduluri You're welcome, cheers! – Alex Mamo Oct 15 '18 at 08:37
  • Possible duplicate of [Getting a specific category of data from firebase](https://stackoverflow.com/questions/51406414/getting-a-specific-category-of-data-from-firebase) – RileyManda Feb 28 '19 at 07:19

1 Answers1

1

If you want to get sermons with sermoncategory as 2, you may use orderByChild() query like this:

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());
        }
    });
PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20