我正在通过按下带有(下载)图标的imageview下载文件。下载后,图标变为(选中)图标。
如何检查imageview是否显示选中的图标以防止再次下载。
我目前无法使用的方法:
if (holder.imgFileAttachment.getDrawable() == context.getResources().getDrawable(R.drawable.downloaded)) {
//Prevent another download
}
答案 0 :(得分:0)
通过进一步的研究,在使用getDrawable()之后,我可以使用Drawable
类中的getConstantState()获取其中包含的数据。
解决方案:
if (imageView.getDrawable().getConstantState() == context.getResources().getDrawable(R.drawable.a).getConstantState()) {
//contains image a
} else {
// contains another image
}