• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

2 Buttons

  • Thread starter Thread starter DrawlI
  • Start date Start date

How to do this?

  • a

    Votes: 0 0.0%
  • a

    Votes: 0 0.0%

  • Total voters
    0
D

DrawlI

Guest
I tried to create a 2 buttons but when i click options it goes to options and when i click credits it opens options i want to open credits ;-;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.b1);
Button b2 = (Button) findViewById(R.id.b2);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
}
@override
public void onClick(View v) {
switch (v.getId()){
case R.id.b1:
openOptions();
break;
case R.id.b2:
openCredits();
break;
}
}
public void openOptions(){
Intent option = new Intent(this, Options.class);
startActivity(option);
}
public void openCredits(){
Intent credit = new Intent(this, Credits.class);
startActivity(credit);
}
 
Back
Top Bottom