繁体   English   中英

我如何检查 imageview 是否为空

[英]How can i check if imageview is empty or not

我有一个具有表单的应用程序,并且有一些字段需要用户填写,我想禁用“下一步”按钮,直到用户填写这些字段。

字段是:(iamgeView, EditText,Spinner..)

我知道如何检查文本编辑但我如何检查用户是否填充了图像和微调器(图像视图将让用户从本机图库中选择图像)

我想要什么:我如何检查用户是否填充了图像和微调器? 这是我检查编辑文本的代码

  private boolean checkEditText2(EditText edit) {
    return edit.getText().length() == 0;
}

在 xml 文件中,您的图像没有android:src=""android:backgroud=""

   if(null!=imgView.getDrawable())
     {
        //imageview has image
     }else{
       //imageview has no image  
     }

尽管已接受的答案提出了建议,但您应该执行以下操作:

publie static boolean hasNullOrEmptyDrawable(ImageView iv)
{
    Drawable drawable = iv.getDrawable();
    BitmapDrawable bitmapDrawable = drawable instanceof BitmapDrawable ? (BitmapDrawable)drawable : null;

    return bitmapDrawable == null || bitmapDrawable.getBitmap() == null;
}

请参阅我之前的回答中的解释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM