簡體   English   中英

如何檢查 imageview 是否具有特定類型的圖像

[英]How to check if an imageview has a specific type of image

我正在下載一個文件,方法是按下帶有(下載)圖標的 imageview。 下載后圖標變為(選中)圖標。

如何檢查 imageview 是否顯示選中圖標以防止再次下載。

我目前沒有奏效的方法:

if (holder.imgFileAttachment.getDrawable() == context.getResources().getDrawable(R.drawable.downloaded)) {
      //Prevent another download
}

通過進一步的研究,在使用getDrawable()之后,我能夠使用getConstantState()Drawable class 中獲取它包含的數據。

解決方案:

if (imageView.getDrawable().getConstantState() == context.getResources().getDrawable(R.drawable.a).getConstantState()) {
    //contains image a
} else {
    // contains another image
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM