簡體   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