title: How to Comparing two drawables in android
body: <p>How can I get the drawable imgageID of  Images  on the ImageButtons to compare????? I think  i have a problem in the If{loop} thar i comare klikk1 with klikk2. here is meg code.
  Any one can help with that please? i think i have problem with test method.</p>
  
  <pre><code>int turnone;
  int turntwo;
  boolean turnstate = true;
  ImageButton klikk1;
  ImageButton klikk2;
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_newgame);
  
      final int[] imageIDs = {
              R.drawable.dog,
              R.drawable.eagle,
              R.drawable.elefant,
              R.drawable.kanin,
              R.drawable.gurilla,
              R.drawable.lion,
              R.drawable.dog,
              R.drawable.eagle,
              R.drawable.elefant,
              R.drawable.kanin,
              R.drawable.gurilla,
              R.drawable.lion,
  
      };
      int[] buttonIDs = {
              R.id.btn_1,
              R.id.btn_2,
              R.id.btn_3,
              R.id.btn_4,
              R.id.btn_5,
              R.id.btn_6,
              R.id.btn_7,
              R.id.btn_8,
              R.id.btn_9,
              R.id.btn_10,
              R.id.btn_11,
              R.id.btn_12
      };
  
      Random r = new Random();
      ArrayList&lt;Integer&gt; printedImagesIDs = new ArrayList&lt;&gt;();
  
      ArrayList&lt;ImageButton&gt; buttons = new ArrayList&lt;ImageButton&gt;();
  
      //fyller buttons
      for(int i = 0; i &lt; buttonIDs.length; i++){
          ImageButton temp = (ImageButton) findViewById(buttonIDs[i]);
          buttons.add(temp);
      }
  
      //populerer buttons med images
      for(int i = 0; i &lt; buttons.size(); i++) {
          int random = r.nextInt(buttons.size());
          while(printedImagesIDs.contains(random))
              random = r.nextInt(buttons.size());
  
          buttons.get(i).setImageResource(imageIDs[random]);
          printedImagesIDs.add(random);
      }
  
      final ArrayList&lt;ImageButton&gt; final_buttons = buttons;
  
      Handler handler = new Handler();
      handler.postDelayed(new Runnable() {
          public void run() {
              flipImages(final_buttons);
          }
      }, 2000);
  
  }
  
  public void flipImages(ArrayList&lt;ImageButton&gt; buttons){
      for(int i = 0; i &lt; buttons.size(); i++){
          Drawable temp = buttons.get(i).getDrawable();
          temp.setAlpha(0); //0-255, 0 = gjennomsiktig, 255 = fullt synlig
      }
  }
  
  public void test(View view){
      ImageButton btn = (ImageButton)findViewById(view.getId());
      Drawable draw = btn.getDrawable();
      draw.setAlpha(255);
      if(turnstate){
          turnone = btn.getId();
          klikk1 =btn;
          turnstate = false;
      }
      else {
          turntwo= btn.getId();
          klikk2 =btn;
  
          /*mRememberPwd.getDrawable().getConstantState().equals
          (getResources().getDrawable(R.drawable.login_checked).getConstantState())*/
  
         if(klikk1.getDrawable().getConstantState().equals(klikk2.getDrawable().getConstantState())){//found pair
             turnstate = true;
          }
          else {
              Handler handler = new Handler();
              handler.postDelayed(new Runnable() {
                  public void run() {
                      Drawable draw1 = klikk1.getDrawable();
                      Drawable draw2 = klikk2.getDrawable();
                      draw1.setAlpha(0);
                      draw2.setAlpha(0);
                  }
              }, 2000);
  
          }
          turnstate = true;
      }
  
  }
  </code></pre>
  
  <p>}</p>