Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is quick way to check if ImageView has bitmap assigned?

Tags:

android

I need to quickly and safely check if an android.widget.ImageView currently has a Bitmap of non zero value attached. What is a quick way to do this.

Update my image view is set initially drawable set to "logo.png" so if I know that it is currently set to logo.png than I know that the bitmap has not yet been set. So how can I check if background drawable is currently logo.png

Thanks

like image 264
NextDroid Avatar asked Dec 12 '22 19:12

NextDroid


2 Answers

Use getDrawable() method, if it return null then nothing assigned

if( mImageView.getDrawable() != null){

  //Image Assigned

}else{
  //nothing assigned

}
like image 77
Changdeo Jadhav Avatar answered Feb 24 '23 07:02

Changdeo Jadhav


Assign ImageView to variable in onCreate:

someImage = (ImageView) findViewById(R.id.imageView);

Then a simple if-else statement:

Bitmap bm = ((BitmapDrawable) someImage.getDrawable()).getBitmap();

                boolean hasDrawable = (bm != null);
                if(hasDrawable) 
                {
                    hasImage();
                }
                else 
                {
                    Toast.makeText(AppSettings.this, "No Bitmap", Toast.LENGTH_SHORT).show();
                }
like image 23
Ben Cassell Avatar answered Feb 24 '23 06:02

Ben Cassell