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........
Display an Image in Java Using JLabel. JLabel extends JComponent , and we can attach this component to a JFrame . To read the image file, we use the File class and pass the path of the image. Next we convert the image to a BufferedImage object using ImageIO. read() .
Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.
android.widget.ImageSwitcher. ViewSwitcher that switches between two ImageViews when a new image is set on it.
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);
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);
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