So I’m trying to write an activity that has two spinners and a button, when the two spinners are selected and the button pressed it’ll take you to another activity. Except for one combination, which should produce a Toast saying that you can’t do this.
Anyway, this is the code:
public void onClick(View v) {
String spinnerchoice1 = ("spinner1Value");
String spinnerchoice2 = ("spinner2Value");
if((spinnerchoice1.equals("Walking")) && (spinnerchoice2.equals("Hiking"))){
Toast.makeText(getBaseContext(), "I'm sorry, this is not possible.", Toast.LENGTH_LONG).show();
}else{
Intent i = new Intent(GetDirections.this.getApplicationContext(), DirectionDisplay.class);
i.putExtra("spinner1Value", transportSpinner.getSelectedItem().toString());
i.putExtra("spinner2Value", locationSpinner.getSelectedItem().toString());
GetDirections.this.startActivity(i);
}
}
Can anyone tell me where I’m going wrong?
Thanks
You are comparing two hard-coded strings, the if condition will never execute. Change the code to: