How to load and display the images in the folder with different name in the ImageView in android?
<p>These is the code snippet of an Android program... Where I am trying to display images in an ImageView. But while making it dynamic by removing the constant values the program is giving me an error which I am not able to resolve... </p>

<pre><code>public void onCreate(Bundle savedInstanceState) 
{
        Class&lt;drawable&gt; resources = R.drawable.class;
        Field[] fields = resources.getFields();

        for (Field field : fields) 
        {
            imgName[n]=field.getName();
            n++;
        }
        while(cnt!=n)
        {
            int resID = getResources().getIdentifier(imgName[cnt], "drawable","com.example.imageviewpckg");
            imgList[cnt]=resID;
            cnt++;
        }
}
</code></pre>

<p>Can we write the above code for initializing the <code>int</code> Array with ImageView <code>ids</code> instead of the fixed initialization as show below code of line...</p>

<p>This below line gives me the correct output:</p>

<pre><code>int imgList[] ={
                  R.drawable.img1,
                  R.drawable.img2,
                  R.drawable.img3,
                  R.drawable.img4,
                  R.drawable.img5,
                  R.drawable.img7
                };
</code></pre>
