I am using multiple ListViews to create multiple options for the End-user and now I have to use a button to direct the user to his/her desired page. This is my code -
spinner = (Spinner) findViewById(R.id.spinner);
spinner1 = (Spinner) findViewById(R.id.spinner1);
String[] List_view1 = new String[]{
"Choose your option...",
"All",
"1",
"2"
};
String[] List_View2 = new String[]{
"Choose your option...",
"All",
"4",
"5",
"6"
};
final List<String> list= new ArrayList<>(Arrays.asList(List_view1));
final List<String> list1= new ArrayList<>(Arrays.asList(List_View2));
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
String spi = spinner.getSelectedItem().toString();
String spi1 = spinner1.getSelectedItem().toString();
if (spi == "Choose your option..." || spi1 == "Choose your option...")
{
Toast.makeText(MainActivity.this, "Please make sure you have given every input, " += " and not leaving even one empty", Toast.LENGTH_SHORT).show();
}
if (spi == "1" || spi == "2" || spi1 == "5" || spi1 == "6")
{
Intent intent = new Intent(getApplicationContext(), CollegeListAES1.class);
startActivity(intent);
}
if (spi == "2" || spi == "3" || spi1 == "4")
{
Intent intent = new Intent(getApplicationContext(), CollegeListAES2.class);
startActivity(intent);
}
break;
}
}
});
}
Now if I select 2 and 4, then it will go to CollegeListAES2, but it is going to CollegeListAES1. surprisingly if I make another if statement like this, the same problem occurs. Talking about first of statement, which is "Choose your Option..." is perfectly working. How to get rid of this and go to the proper page?