Java – Compare Imageview and R.drawable

Compare Imageview and R.drawable… here is a solution to the problem.

Compare Imageview and R.drawable

I want to check if an Imageview has a specific R.drawable, and if so, change it with another image. But it doesn’t work that way.

XML code

 <ImageView
        android:id="@+id/Picture"
        android:src="@drawable/apicture"
 </ImageView>

Java code

Image = (ImageView) findViewById(R.id.Picture);

public void coolMethod()
{
    if(Image.equals(R.drawable.apicture){

Image.setImageResource(R.drawable.anotherpicture);
     }
}

Related Problems and Solutions