Una solucion muy practica si necesitas saber la imagen de fondo de un boton, es usar el campo tag
que tienen todas las vistas para guardar el id del recurso de la imagen R.drawable.foto
.
Y cuando necesites compararlo comparas directamente el tag con el id de recurso que corresponda.
ImageButton ib1 = ...;
int tag = ib1.getTag();
int rid = R.drawable.foto;
if (tag == rid){
//Es el boton correcto.
}
En el xml tu button deberia verse algo asi:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@drawable/image"
android:background="@drawable/image" />
Drawable
, por ejemplo:Drawable bg = ib1.getBackground();
y luego podrías comparar:if (bg==R.drawable.foto ) { //...código}