title: Button selection in Android
body: <p>I have to create button options where each button performs specific task. So how to do the  button selection. The code I tried is here. </p>
  
  <pre><code>            Button b1      
          b1.setOnClickListener(new Button.OnClickListener(){
  
      public void onClick(View v) {
                if(v.getId()==R.id.button1)
                {      //do something
                         }
                        if(v.getId()==R.id.button2)
                {      //do something
                            }
                         });
  </code></pre>
  
  <p>For single button function its working fine with this code.</p>
  
  <pre><code>           Button b1= (Button)findViewById(R.id.button1);        
          b1.setOnClickListener(new Button.OnClickListener(){
  
      public void onClick(View v) {
                if(v.getId()==R.id.button1)
                {      //do something
                         }
                        }});
  </code></pre>