two spinner in one activity
use
spin2.setAdapter(bb);
instead of
spin.setAdapter(bb);
currently you are setting Adapter for second spinner
Don't add the implementation to your Activity class
Create two inner classes that each handle one of the spinners
public class CreateComboBox extends Activity implements AdapterView.OnItemSelectedListener
{
TextView selection;
TextView selection2;
String[] countries = {"Amerika","Argentina","Brazil"};
String[] city = {"London","Paris","Buenos Aires"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
Spinner spin = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, countries);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
spin.setOnItemSelectedListener(new CountriesSpinnerClass());
selection2 = (TextView) findViewById(R.id.selection2);
Spinner spin2 = (Spinner) findViewById(R.id.spinner2);
ArrayAdapter<String> bb = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, city);
bb.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(bb);
spin2.setOnItemSelectedListener(new CitiesSpinnerClass());
}
class CountriesSpinnerClass implements AdapterView.OnItemSelectedListener
{
void onItemSelected(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(v.getContext(), "Your choose :" + countries[position],Toast.LENGTH_SHORT).show();
}
}
class CitiesSpinnerClass implements AdapterView.OnItemSelectedListener
{
void onItemSelected(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(v.getContext(), "Your choose :" + city[position],Toast.LENGTH_SHORT).show();
}
}
}