I need to show an image by using the file name only, not from the resource id.
ImageView imgView = new ImageView(this);
imgView.setBackgroundResource(R.drawable.img1);
I have the image img1 in the drawable folder. I wish to show that image from the file.
How can I do this?
Labeeb is right about why you need to set image using path if your resources are already laying inside the resource folder ,
This kind of path is needed only when your images are stored in SD-Card .
And try the below code to set Bitmap images from a file stored inside a SD-Card .
And include this permission in the manifest file:
How To Show Images From Folder path in Android
Very First: Make Sure You Have Add Permissions into Mainfest file:
## :Make a Class MyGallery
public class MyGallery extends Activity {
}
Now create its Xml Class
Also Make Adapter galleryadapter.xml
To see the Image in Detail create a new Class ImageDetail:
}
Create its xml image_detail.xml
Add your own Drawable to Selector class,and create it res>drawable>selector_shareimage.xml
onLoadImage Full load
// else {
All the answers are outdated. It is best to use picasso for such purposes. It has a lot of features including background image processing.
Did I mention it is super easy to use: