I created a drop-down menu and i overrided the onItemSelected method:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), item, Toast.LENGTH_LONG).show();
}
With the above code if i select an item then it shows a toast with selected item. I tried to edit the code in this way:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), item, Toast.LENGTH_LONG).show();
Intent intent = new Intent(Selection.this, MainActivity.class);
startActivity(intent);
}
Why it doesn't allow me to select an item and go to MainActivity instead?