I have a class called Menu and inside that class I want to place a menu of buttons such as buttonA, buttonB, buttonC, and so on. However when I run the app on my phone I cant tap buttonB before I tap buttonA. If I tap buttonA first, I can choose buttonA or buttonB all I want. The question is how do you separate the buttons in the Menu class to be able to tap any button at any time?
package com.emods.app1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnA = (Button) findViewById(R.id.button1);
btnA.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent ("com.emods.app1.BUTTONA"));
Button btnB = (Button) findViewById(R.id.button2);
btnB.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent ("com.emods.app1.BUTTONB"));
}
});
}
});
}
}
You need to take your btnB and place it outside your onClick event for btnA. Currently you have your declaration for btnB inside your onClick event for btnA.