Как выше уже было указано:
https://developer.android.com/guide/topics/ui/cont...public class MainActivity implements AdapterView.OnItemSelectedListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
....
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
...
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
parent.getItemAtPosition(position);
switch (position) {
case 0:
return;
//этот будет срабатывать сразу при отображении спиннера
case 1:
Intent intent = new Intent(this, Main2Activity.class);
startActivity(intent);
return;
case 2:
Intent intent = new Intent(this, Main3Activity.class);
startActivity(intent);
return;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
strings.xml:
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
</string-array>