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."
If you're working with an Android application, this source code works as a way to load an image from a file: Bitmap bitmap = BitmapFactory. decodeFile(pathToPicture);
ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics. drawable.
For most cases, we recommend that you use the Glide library to fetch, decode, and display bitmaps in your app. Glide abstracts out most of the complexity in handling these and other tasks related to working with bitmaps and other images on Android.
You could try this:
int cnt = 1;
//Bitmap bitmap = BitmapFactory.decodeFile("temp" + cnt + ".jpg");
int imageResource = getResources().getIdentifier("drawable/temp" + cnt + ".jpg", null, getPackageName());
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), imageResource);
imageView.setImageBitmap(bitmap);
cnt++;
Hope that's what you were looking for.
Why not something like
File f = new File(PathToFiles + "/temp" + cnt + ".jpg");
if (f.exists()) {
Drawable d = Drawable.createFromPath(f);
imageview.setImageDrawable(d);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With