Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to have multiple buttons in one activity
  2. public class NL extends Activity {
  3.  
  4.  
  5.  
  6.      public void onCreate(Bundle savedInstanceState) {
  7.             super.onCreate(savedInstanceState);
  8.             setContentView(R.layout.main);
  9.           Button b1=(Button)findViewById(R.id.Button01);
  10.           Button b2=(Button)findViewById(R.id.Button02);
  11.           b1.setOnClickListener(new View.OnClickListener() {
  12.  
  13.             public void onClick(View v) {
  14.                 Intent myintent2 = new Intent(NL.this,Button1.class);
  15.                 startActivity(myintent2);
  16.  
  17.             }
  18.         });
  19.           b2.setOnClickListener(new View.OnClickListener() {
  20.  
  21.                 public void onClick(View v) {
  22.                     Intent myintent2 = new Intent(NL.this,Button2.class);
  23.                     startActivity(myintent2);
  24.  
  25.                 }
  26.             });
  27.     }
  28. }
  29.        
  30. Button button3 = (Button) getViewById(R.id.3)
  31.        
  32. button3.setOnClickListener(new OnClickListener(){
  33.   public void onClick(View v){
  34.     //place code to execute here
  35.   }
  36. });
  37.        
  38. Intent intent = new Intent(this, TheActivityClassYouWantToLaunch.class);
  39. startActivity(intent);