title: Android view comparing two views for equality
body: <p>I have 4 buttons on a layout, and for each of the buttons, they have the attribute:</p>
  
  <p><code>android:onClick="numberChosen"</code></p>
  
  <p>now, what I had planned on doing was that in my activity (which uses a layout that has the 4 buttons), I have something like:</p>
  
  <pre><code>public class Blah extends Activity{
      String fileName;
      Button one;
      @Override
      public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_number_players_selection_screen);
          one = (Button) findViewById(R.id.number_players_one);
      }
  
  
      public void numberChosen(View v){
          if(v == one){                              // &lt;-------- first way
              System.out.println("first way");      
          }
          if(v.getId()==R.id.number_players_one){    // &lt;--------  second way
              System.out.println("second way");
          }
      }
  }
  </code></pre>
  
  <p>if you take note of what happens in the method <code>numberChosen</code>, between these two ways, which one is better? or are they both exactly doing the same thing?</p>
  
  <p>on a side note, is doing <code>android:onClick="numberChosen"</code> any better or worse than just setting the <code>View.onClickListener</code> instead?</p>