我有一個Android微調,當用戶按下「返回鍵」時,顯示微調的選擇面板時,我想聽的事件。我實現了OnItemSelectedListener,但onNothingSelected(AdapterView arg0)沒有被調用時, 。
爲什麼spinner中的onNothingSelected未被調用?
我只是想聽用戶什麼都沒有選擇(或選擇面板消失)的事件。
有沒有正確的方法來做到這一點?
謝謝!
Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.colors, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(
new OnItemSelectedListener() {
public void onItemSelected(
AdapterView<?> parent, View view, int position, long id) {
showToast("Spinner1: position=" + position + " id=" + id);
}
public void onNothingSelected(AdapterView<?> parent) {
showToast("Spinner1: unselected");
}
});
這是Android 2.2的SDK的樣本,它也沒有表現出 「Spinner1:未選中」 當選擇面板中消失。
真誠感謝Qberticus! 它似乎是現在處理它的唯一方法。 – RobertKing 2010-08-13 07:29:37
@Qberticus我想我不明白什麼時候onNothingSelect會被調用?如果現在當你什麼都沒有選擇,那麼什麼時候? – 2013-09-04 19:29:09