I’ve reviewed my code several times and tried different “solutions”, obviously none of them worked. The problem is that listener never get’s fired when an item is clicked. I found out that when an item is clicked this appears in Logcat:
Window already focused, ignoring focus gain of:
com.android.internal.view.IInputMethodClient$Stub$Proxy@40683498
The Spinner is created dynamically in a function fired by Button.
Code :
public void showFilterCountries(View v){
Spinner country_list=new Spinner(this);
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, countries);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
country_list.setAdapter(adapter);
country_list.setPrompt("Select a country");
country_list.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
Log.d("","selected");
}
public void onNothingSelected(AdapterView<?> arg0) {
Log.d("","none selected");
}
});
country_list.performClick();
}
I solved using AlertDialog.Builder instead of Spinner (which is the right way), like this:
https://stackoverflow.com/a/7635966/1181261