How to compare name of two images in Android Studio

Asked

Viewed 188 times

0

Having a

imagem = (ImageView) findViewById(R.id.imageViewId);

How do I know if the current image has the name x or y?

I tried some ways with the equals and stuff, but it didn’t work....

if (imagem.equals("nome")){...
  • But the idea is to compare images ? It was assigned directly in the layout?

  • The image will be set dynamically. If the chosen one is X I want to do an action...

  • 1

    What exactly are you trying to do?

1 answer

1

I suppose when you say "image name" you’re referring to the ID assigned by android:id or setId(), in this case R.id.imageViewId.

If so, use the method imagem.getId() to obtain the assigned ID:

if (imagem.getId() == R.id.imageViewId){...
  • Why not the equals() ?

  • 1

    @RBZ equals(), in this case, serves to verify if they are the same instance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.