How To Show Image In Android Using Java Code
I am try to show a image in android using java code not xml. I have done it using xml file but my requirement is using java code to get more funcionality . thanks in advance for h
Solution 1:
IF you want to load image from drawable folder, you can using:
ImageView imgView=(ImageView) findViewById(R.id.imgView);
Drawable drawable = getResources().getDrawable(R.drawable.img);
imgView.setImageDrawable(drawable);
Solution 2:
You have to use one default imageview in android xml when you are running app that time in activity you have to write this code so it will replace you image with another image. Check following code
ImageView imgView=(ImageView) findViewById(R.id.default_imgView);
imgView.setImageResource(R.drawable.yourimagename);
Solution 3:
Using Drawable class you can show Image
Drawable drawable = Drawable.createFromPath(imagePath);
image.setImageDrawable(drawable);
Solution 4:
I hope you are using ImageView to display the image in XML file with id iv.
In java file
ImageView iv = (ImageView)findViewById(R.id.iv);
iv.setImageResource(R.drawable.image1); // image1 is image file available in drawables folder
Solution 5:
use ImageView and learn more about it from here imageview referecne
you can set image from bitmap,uri, from resources, etc...
Post a Comment for "How To Show Image In Android Using Java Code"