我已經檢查了幾次我的代碼,並嘗試了不同的「解決方案」,顯然他們都沒有工作。問題在於,點擊某個項目時,偵聽器不會被觸發。我發現,單擊某個項目時,這個出現在logcat中:微調OnItemSelected不工作
窗口已經集中,忽略了聚焦增益: [email protected]
Spinner是由Button觸發的函數動態創建的。
代碼:
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();
}
哪裏在UI上添加country_list? –
我從不在用戶界面上顯示我的Spinner。我只需要使用country_list.performClick()顯示的「選擇列表」。 –
我會嘗試刪除匿名內部類(您的偵聽器設置),而不是讓你的類實現OnItemSelectedListener。然後把你的物品選定的邏輯放在重寫的方法中。只是一個猜測。 –