我已经多次检查我的代码并尝试了不同的“解决方案”,显然它们都不起作用。问题是当一个项目被点击时,监听器永远不会被解雇。我发现当单击一个项目时,它会出现在 Logcat 中:
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40683498
Spinner 是在 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();
}
最佳答案
我使用 AlertDialog.Builder 而不是 Spinner(这是正确的方法)解决了问题,如下所示:
关于android - 微调器 OnItemSelected 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10901393/