Android - how can I dynamically load drawables (pictures)? Names not known until run-time
<p>I've searched Google and this website many times, but can not find a solution to my question.</p>

<p>First, I understand, you can load images using something like:</p>

<pre><code>int image = R.drawable.icon; (assuming there's a file called 'icon.png')
</code></pre>

<p>and I've read about, and tried using:</p>

<pre><code>getResources().getIdentifier("resname", "restype", com.example.whatever);
</code></pre>

<p>But, here's what I'm unable to do:
I want to be able to have pictures in the /res/drawable folder (I believe that's the correct folder), WITHOUT KNOWING ANY OF THE NAMES OF THE FILES, and load them dynamically - at run-time.</p>

<p>One (of the many) things I've tried is (something like):</p>

<pre><code>int[] images = new int[numberOfImages];
for( 0 to numberOfImages )
{
    images[i] = 
        getResources().getIdentifier("resname", "restype", com.example.whatever);
}
</code></pre>

<p>This returns 0 EVERY TIME, so it's not going to work</p>

<p>I'd like to get the name and integer identifier for every picture in the /res/drawables folder.  Can this be done WITHOUT KNOWING ANY FILE NAMES?</p>

<h2>----------------------------------------------------------------------</h2>

<p>[adding this after the question was resolved to help anyone that may run into the same issue in the future.  It just shows that it does in fact work.]</p>

<pre><code>    Class resources = R.drawable.class;
    Field[] fields = resources.getFields();
    String[] imageName = new String[fields.length];     
    int index = 0;
    for( Field field : fields )
    {
        imageName[index] = field.getName();
        index++;
    }

    int result = 
            getResources().getIdentifier(imageName[10], "drawable", "com.example.name");
</code></pre>
