Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set image in imageview in android?

Tags:

I want to show an image in imageview so I made a folder - drawable in res and put my image there. Something like apple.png. Then I use this code:

ImageView iv= (ImageView)findViewById(R.id.img_selected_image); String path = getApplication().getFilesDir().getAbsolutePath(); InputStream is = new FileInputStream(path + "/apple.png"); Drawable icon = new BitmapDrawable(is); Log.i("Fnord", "width="+icon.getIntrinsicWidth()+      " height="+icon.getIntrinsicHeight()); iv.setImageDrawable(icon); 

But when i run it, it said there isn't any image by apple.png name in data/data/package-name/files. I think i put my image in inappropriate place. Where should i put my image ?

like image 893
shadi Avatar asked Nov 22 '12 13:11

shadi


People also ask

How do I set activity images?

xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView. Select the image you want press Ok you can see the image on the Design view.

How do you insert a picture into drawable?

To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.

What is the image view in android?

In Android, ImageView class is used to display an image file in application. Image file is easy to use but hard to master in Android, because of the various screen sizes in Android devices.


1 Answers

you can directly give the Image name in your setimage as iv.setImageResource(R.drawable.apple); that should be it.

like image 187
Anuj Avatar answered Oct 07 '22 11:10

Anuj