Java 我如何检查 imageview 是否为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9706885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i check if imageview is empty or not
提问by user1257040
i have an application that has form and there is some fields the user should fill it ,i want to put the button "Next" disable until the user fill this fields.
我有一个具有表单的应用程序,并且有一些字段需要用户填写,我想禁用“下一步”按钮,直到用户填写这些字段。
the fields is:(iamgeView, EditText,Spinner..)
字段是:(iamgeView, EditText,Spinner..)
i know how to check the text Edit but how can i check if the user fill the image and spinner or not (image view will let the user choose an image from native gallery)
我知道如何检查文本编辑但我如何检查用户是否填充了图像和微调器(图像视图将让用户从本机图库中选择图像)
What i want: how can i check if the user fill the image and spinner or not? this is my code to check the Edit Text
我想要什么:我如何检查用户是否填充了图像和微调器?这是我检查编辑文本的代码
private boolean checkEditText2(EditText edit) {
return edit.getText().length() == 0;
}
回答by Samir Mangroliya
In xml file your image have not android:src=""
andandroid:backgroud=""
在 xml 文件中,您的图像没有android:src=""
并且android:backgroud=""
if(null!=imgView.getDrawable())
{
//imageview has image
}else{
//imageview has no image
}
回答by Alexander Abakumov
Despite what the accepted answerproposes, you should do the following instead:
尽管已接受的答案提出了建议,但您应该执行以下操作:
publie static boolean hasNullOrEmptyDrawable(ImageView iv)
{
Drawable drawable = iv.getDrawable();
BitmapDrawable bitmapDrawable = drawable instanceof BitmapDrawable ? (BitmapDrawable)drawable : null;
return bitmapDrawable == null || bitmapDrawable.getBitmap() == null;
}
See explanation in my previous answer.
请参阅我之前的回答中的解释。