If there is an array int[] = new int[]{drawable1, drawable2}; then the elements contained in it are already int themselves.

I pull the drawable out of the button, like this:

 Drawable d1 = SG6Button1.getDrawable(); 

The question is how do I convert it to an int ? This is necessary to compare with an array like the one above.

    1 answer 1

    It seems to me that this is impossible. But there is an alternative approach - Record, in which View you have installed which Drawable .
    This can be implemented, for example, by adding matches to Map<View, Integer> , in which the key is View , and the value is the id resource.

    Alternatively, each View has a Tag field ( Object getTag() , void setTag(Object tag) ), into which you can write the resource id when setting it to View , and to do something like this for checking:

     SG6Button1.setTag(R.drawable.drawable1); ... Integer id = (Integer ) SG6Button1.getTag(); if(id != null) { //это значит, что можно использовать id } 
    • Thank. I also thought about this method. - St. Ivan
    • Tell me, will there be R.drawable.drawable1 which I set in setTag R.drawable.drawable1 which is contained in the array int[] = new int[]{R.drawable.drawable1, R.drawable.drawable2}; ? After all, they are both Int . - St. Ivan
    • one
      @ VANECHKA, yes, it will. You, by the way, better check it yourself in debug or using logs, for example :) - Vladyslav Matviienko