Search code examples
androidandroid-widgetimageview

Load Images in ImageView in Android


In my application....there are some images like temp1.jpg, temp2.jpg .....upto temp35.jpg,

so on button clicking, i want to load one-by-one image in ImageView .... i want to do like:

cnt=1;
imagename="temp" + cnt + ".jpg";
cnt++;

so my confusion is that "is there anyway to load an image in imageview from string(imagename variable) like temp1.jpg,etc."


Solution

  • I implemented below solution and it's working for me:

    while(cnt!=n)
    {
     String icon="temp" + cnt;
     int resID =
     getResources().getIdentifier(icon,"drawable","testing.Image_Demo");
     imageView.setImageResource(resID);
     cnt++; 
    }