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
Use getDrawable() method, if it return null then nothing assigned
if( mImageView.getDrawable() != null){
//Image Assigned
}else{
//nothing assigned
}
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();
}
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