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 ?
Did you add your activity in manifest.xml
<activity android:name=".YourActivity" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With