Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if an ImageView is attached with image in android

Tags:

android

I am setting an image to ImageView in android code not in xml, but could not make out how to check whether that image has been set in or not in java.

Tried with imageViewOne.getVisibility() == 0 but it is not working

If image has been set to ImageView then I am attaching that image for sending mail.

like image 299
Mukunda Avatar asked Feb 02 '12 14:02

Mukunda


People also ask

How do you get a resource image?

You can use imageButton. getDrawable() to get the drawable of the ImageButton object and then use setImageDrawable() instead of setImageResource() .

Can ImageView display video?

You can add ImageView and VideoView in RelativeLayout and set ImageView to invisible and VideoView to visible and vice-versa and you can play video on onClick.


1 Answers

imageViewOne.getVisibility() == 0

use this instead:

imageViewOne.getDrawable() == null 

From documentation:

/**
* Gets the current Drawable, or null if no Drawable has been
* assigned.
*
* @return the view's drawable, or null if no drawable has been
* assigned.
*
*/
public Drawable getDrawable() {

}

like image 101
PC. Avatar answered Sep 20 '22 11:09

PC.