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 help........
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 help........
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);
use ImageView and learn more about it from here imageview referecne
you can set image from bitmap,uri, from resources, etc...
You can use the following code
ImageView img = new ImageView(this); /*In new version of Android Studio you don't need to do castling.*/
img = findViewById(R.id.android_image);
Drawable img_drawable=getResources().getDrawable(R.drawable.draw_img);
img_cookie.setImageDrawable(img_drawable);
The code below worked fine for me.
ImageView imageViewVar = (ImageView) findViewById(R.id.imageViewId);
imageViewVar.setImageResource(R.drawable.yourImgFile);