Retrieve data from firebase database with certain conditions
<p>Good day, I am using Android studio to create a question and answer based game and I have a 2 things that I am struggling with. I have a firebase database with the following structure:</p>

<pre><code>database name{
    answers{
         1{
            answer_option_1: .....
            answer_option_2: .....
            answer_option_3: .....
            answer_option_4: .....
           }
         2{
            answer_option_1: .....
            answer_option_2: .....
          }
</code></pre>

<p>and so it carries on similar to the above shown structure.
My question is regarding how I could retrieve the answer options and store them in their respective variables? such as:</p>

<blockquote>
  <p>Option1 = answer_option_1</p>
</blockquote>

<p>Is there a way to count the number of children under the parent, such as, it should tell me that under the parent 2, there are 2 children?</p>

<p>My code for retrieving a single value is as follows:</p>

<pre><code> mDatabase.child("answers").child(num).child("answer_option_1").addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            Option1 = dataSnapshot.getValue().toString();
            option1.setText(Option1);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
</code></pre>

<p>where <strong>mDatabase</strong> is the reference to my Firebase Database and <strong>num</strong> is a random value to retrieve a random question . I have repeated the above code a 4 times for the 4 options, but when I have 2 options, as mentioned and shown in the database structure above, my app stops working. </p>

<p>All help will be highly appreciated.</p>