Spinner setonitemselectedlistener is not called
Posted
by
Gabrielle
on Stack Overflow
See other posts from Stack Overflow
or by Gabrielle
Published on 2012-10-15T09:35:34Z
Indexed on
2012/10/15
9:36 UTC
Read the original article
Hit count: 203
I have a strange problem. I need to do something when an item from spinner is selected.
Here is my code :
language = (Spinner) findViewById(R.id.current_language_text);
ArrayAdapter adapter = new ArrayAdapter(this,
com.Orange.R.layout.my_spinner_textview, languages);
adapter.setDropDownViewResource(com.Orange.R.layout.multiline_spinner_dropdown_item);
language.setAdapter(adapter);
language.setSelection(Integer.valueOf(language_id) - 1);
language.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
System.out.println("position "+position);
Toast.makeText(Settings.this, "Hello Toast",Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
The problem is that onItemSelectedListener is not called. I put System.out.println in onItemSelected() but I don't get it in LogCat. I tried with Toast, and I get the same, it doesn't appear. Every time I select an item from spinner, in LogCat I get this warning : Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2b1dabd0
Any idea why onItemSelectedListener is not called ?
© Stack Overflow or respective owner