This is how i define the spinner
s_province = (Spinner) findViewById(R.id.s_province);
ArrayAdapter<String> provinceAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Data.provinces);
provinceAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s_province.setAdapter(provinceAdapter);
s_province.setOnItemSelectedListener(this);
my class is implement from OnItemSelectedListener and i override this methods
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
switch (arg1.getId()) {
case R.id.s_province:
Log.d("here", "there");
break;
default:
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
but the onItemSelect is not triged , why please?
Two things:
If you actually want to check if your method is working put a
Logstatement outside theswitchor in thedefaultcase so that you can be sure the method is being called.You should be using
arg2since that represents position. Make your switch work with positions instead of whatever View is passed. Also rename your variables from the default names Eclipse assigns.arg0,1,2, etcare not helpful for you nor for anyone else looking at your code.Eg