title: Two Button OnClickListeners inside for loop
body: <p>I am self studying Android and now I am learning how to use buttons. I created a simple up counter which works like this: 
  I add the strings (eg. 1 2 3) in different text fields. Then I want to compaire those in pairs(1 with 2, 1 with 3, 2 with 3). The first string element is written on the first button, second on the second and after i press any of those buttons, the tags on the buttons has to change (if there was 1 and 2 so it should change to 1 and 3 or 2 and 3 etc) and the string element gets a higher rank. Everything seems to work well, but I think I am doing huge mistake with adding buttons. Can anyone help me? :) Can I add button listeners like I did in code bellow? :) Thank You!</p>
  
  <pre><code>public void counter() 
  {
      int i = 0;
      int a = i + 1;
  
      for ( i = 0; i &lt; candidates.size() - 1; i++ ) 
      {
              Log.d(TAG, "Setting button one tag: " + i );
              button_one.setTag(i);
              button_one.setText(candidates.get(i).name);
  
              for (a = i + 1; a &lt; candidates.size(); a++)
              {
              Log.d(TAG, "Setting button two tag: " + a );
              button_two.setTag(a);
              button_two.setText(candidates.get(a).name);
  
              button_one.setOnClickListener(new View.OnClickListener() 
              {
  
                  public void onClick(View view) {
  
                      /* Read the clicked tag */
                      int tag = (Integer) view.getTag();
  
                      /* Make higher rank */
                      candidates.get(tag).addRank();
                  }
              });
  
              button_two.setOnClickListener(new View.OnClickListener() 
              {
  
                  public void onClick(View view) {
  
                      /* Read the clicked tag */
                      int tag = (Integer) view.getTag();
  
                      /* Make higher rank */
                      candidates.get(tag).addRank();
                  }
              }); 
              }       
      }
  </code></pre>