[英]How to get and compare the image resources of two images in android dynamically?
I need to compare the image resources of two ImageViews and display whether they match or not. 我需要比较两个ImageViews的图像资源并显示它们是否匹配。 I have tried solutions to the similar questions asked in stackoverflow but they are resulting in the crash of my app.
我已经尝试了解决stackoverflow中类似问题的解决方案,但它们导致我的应用程序崩溃。 just mentioning I have used setImageResource to set the image so please post the solution which don't require me to remove setImageResource method
刚刚提到我已经使用setImageResource设置图像,所以请发布不需要我删除setImageResource方法的解决方案
you can compare imageViews in kotlin like this: 您可以像这样在kotlin中比较imageViews:
if(imageView1.drawable.constantState == imageView2.drawable.constantState){
//Do something
}
or if you like in java: 或者,如果您喜欢使用Java:
if(imageView1.getDrawable().getConstantState() == imageView2.getDrawable().getConstantState()){
//Do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.