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

Apps Buttons only work after first button is pressed

ktUK

Newbie
I have an xml page with 3 buttons on all leading to similar xml files. However, the second and third buttons only respond if the first has been pressed (and then you go back a page and press another). If I reverse the order of the buttons in the java file, which ever button is listed first is the one that has to be used befor the others.

Here is my java for the buttons:
________________________________________________________

package converter.units.kitchen;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Menu2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.convertmenu);

Button start = (Button) findViewById(R.id.buttonLitres);
start.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.CONVERTLITRES"));

Button start = (Button) findViewById(R.id.buttonGrams);
start.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.CONVERTGRAMS"));

Button start = (Button) findViewById(R.id.buttonOunces);
start.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.CONVERTOUNCES"));


}
});
}

});
}
});


} }

_____________________________

Any help would be greatly appreciated, the rest of the app has no errors and functions correctly. Thank you very much
 
This is happening because you are instantiating the second and third button inside the onClick method of the first button. Close the first onClick method and do the same to the second and third button
 
Back
Top Bottom