开发者

How to check does image set in ImageView

开发者 https://www.devze.com 2023-01-17 00:08 出处:网络
How can i check does image set in ImageView or no, exists standard methods? ImageView imgV; imgV = 开发者_开发问答(ImageView)findViewById(R.id.imageView);

How can i check does image set in ImageView or no, exists standard methods?

ImageView imgV;
imgV = 开发者_开发问答(ImageView)findViewById(R.id.imageView);

if(imgV != set)  ///!!!!! 
  imgV.setImageBitmap(mBitmap);
else 
  imgV.setImageBitmap(null);


What are you trying to accomplish by calling setImageBitmap(null)? If you're trying to make it such that the ImageView has no bitmap and thus doesn't appear, you should use the getVisibility() and setVisibility() methods in the View class. I'm not sure if this is what you're looking for, but

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

if(imgV.getVisibility() == View.INVISIBLE) {  //or use View.GONE 
  imgV.setImageBitmap(mBitmap);
  imgV.setVisibility(View.VISIBLE);
}
else {
  imgV.setImageBitmap(null);
  imgV.setVisibility(View.INVISIBLE); //or use View.GONE
}


You can check ImageView by,

  if(imageView.getDrawable==null)
   {

            //imageview is set
   }

 else
  {
           //imageview is set
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消