我有一个奇怪的问题。选择Spinner的项目时,我需要做某事。
这是我的代码:
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
}
});
问题是onItemSelectedListener
没有调用。我输入了System.out.println
,onItemSelected()
但我没有在 LogCat 中得到它。我试过了Toast
,我得到了同样的结果,它没有出现。每次我从微调器中选择一个项目时,在 LogCat 中我都会收到以下警告:
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2b1dabd0
知道为什么不调用 onItemSelectedListener 吗?