Button selection in Android

Posted by dreamhigh on Stack Overflow See other posts from Stack Overflow or by dreamhigh
Published on 2012-06-08T10:26:22Z Indexed on 2012/06/08 10:40 UTC
Read the original article Hit count: 321

Filed under:
|

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.

            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
                          }
                       });

For single button function its working fine with this 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
                       }
                      }});

© Stack Overflow or respective owner

Related posts about android

Related posts about android-button