-1

I am facing an issue while matching the src of ImageView with drawable. I am implementing this condition but it does not match:-

if (ivServices.resources == ContextCompat.getDrawable(fragment.activity!!,R.drawable.un_check))

Please help to solve this issue

2 Answers2

0

indication of duplicate

Comparing resources within two drawables

danielp
  • 1
  • 3
  • i think it is duplicate https://stackoverflow.com/questions/36373547/comparing-resources-within-two-drawables/36373569#36373569 – danielp Jul 22 '20 at 10:53
0

How about this: Cast it to Bitmap and compare it. The imageview and variables are different, keep in mind. It worked for me. It is written in Kotlin.

var bmap = Imgview.drawable.toBitmap()  
var myPic=getDrawable(R.drawable.jake_yellow_background_square)?.toBitmap()
        if(bmap.sameAs(myPic)){
            Toast.makeText(this,"It is WORKING",Toast.LENGTH_SHORT).show()
        }else{
            Toast.makeText(this,"It is NOT working", Toast.LENGTH_SHORT).show()
        }
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77