public class MainActivity extends Activity implements
AdapterView.OnItemSelectedListener {
String animalList[] = {"Lion", "Tiger", "Monkey", "Elephant", "Dog", "Cat", "Camel"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spin = (Spinner) findViewById(R.id.animalNamesSpinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, animalList);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
//Performing action onItemSelected and onNothing selected
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
switch (position){
case 0:
Toast.makeText(getApplicationContext(), animalList[position], Toast.LENGTH_LONG).show();
startActivity(new Intent(this, Lion.class));
break;
case 1:
Toast.makeText(getApplicationContext(), animalList[position], Toast.LENGTH_LONG).show();
startActivity(new Intent(this, Tiger.class));
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
I created a spinner. when i run the app its automatically jumps to first activity (Lion.class). what i want is, after Lion be selected on spinner, it goes to that activity. how can I fix it?
i read lots of tutorials but i cant find the answer. i know it must be easy