How to iterate over a Datasnapshot without specifying parent folder/ref
<p>I would like to iterate through a Data snapshot with the following structure;</p>

<pre><code> {
"data" : {
"images" : {
  "fw88v6xu6wybamg9zzt6" : {
    "0550e909-3b30-4f83-9725-02fbe45b74ce" : 3,
    "address" : "http://xxxxxxxxxxxxxxx.jpg",
    "author" : "username1",
    "author_id" : "0550e909-3b30-4f83-9725-02fbe45b74ce",
    "location" : "0",
    "rating" : 3
  },
  "osgm6v7kfcjwogo5uv21" : {
    "0550e909-3b30-4f83-9725-02fbe45b74ce" : 4,
    "address" : "xxxxxxxxxxxxxxxx.jpg",
    "author" : "username1",
    "author_id" : "0550e909-3b30-4f83-9725-02fbe45b74ce",
    "location" : "0",
    "rating" : 4
  },
  "prhpcbrrru7z8x6xtolq" : {
    "0550e909-3b30-4f83-9725-02fbe45b74ce" : 6,
    "address" : "xxxxxxxxxxxxxx.jpg",
    "author" : "username2",
    "author_id" : "0550e909-3b30-4f83-9725-02fbe45b74ce",
    "location" : 0,
    "rating" : 6
  }
},
"locations" : {
  "location1" : {
    "author" : "0550e909-3b30-4f83-9725-02fbe45b74ce",
    "latitude" : 11.42222573,
    "longitude" : 58.4348011
  },
  "location2" : {
    "author" : "0550e909-3b30-4f83-9725-02fbe45b74ce",
    "latitude" : 11.42222573,
    "longitude" : 38.4333311
  }
 }
}
</code></pre>

<p>Specifically what I am doing is getting a snapshot of Data/Images children, so it would be the three entries with the auto generated references such as <code>fw88v6xu6wybamg9zzt6</code>
thus I can not accesses a specific entry to retrieve the address for example of the author, so I made my app get</p>

<pre><code>    Iterable&lt;DataSnapshot&gt; imagesDir = snapshot.getChildren();
</code></pre>

<p>and I am not sure how to go over each entry of this snapshot and retrieve the information for entry without knowing the parent ref. ( <code>fw88v6xu6wybamg9zzt6</code> ) ?</p>

<p>All right well, I got to a <a href="https://stackoverflow.com/questions/30669363/firebase-how-get-to-value-of-parent-node-as-string">post</a></p>

<p>Thankx to Chris, for sending me on the right path to search for it, but still not able to construct the right syntax to reach what I am trying to do.</p>

<p>For now my method is as follow;</p>

<pre><code>  public void onDataChange(DataSnapshot snapshot) {
            for (DataSnapshot child: snapshot.getChildren()) {
                Log.i("MyTag", child.getValue().toString());
                imagesDir.add(String.valueOf(child.getValue()));
            }
            Log.i("MyTag", imagesDir.toString());
</code></pre>

<p>from the first Log I get a string of all the values for each node, and on the second one I constructed an array to include all the nodes.</p>

<p>What i am trying to do is add a specific node ( e.g. address Value) to an ArrayList I declared outside the <code>onDataChange</code> method, everytime it iterates over a child. so by the end of the for loop, I would have three addresses in the arraylist (only the values) in this case.</p>

<p>What is the proper way to construct a for loop in order to do that?</p>

<p>Well, the final code I got to and gave me the right outcome is as following;</p>

<pre><code>              public void onDataChange(DataSnapshot snapshot) {
            for (DataSnapshot child: snapshot.getChildren()) {
                Log.i("MyTag", child.getValue().toString());
                imagesDir.add(child.child("author").getValue(String.class));
            }
            Log.i("MyTag_imagesDirFinal", imagesDir.toString());
</code></pre>