0
我在調整器中調用onItemSelectedListener
,但onItemSelected
中的代碼未被執行。onItemSelectedListener不會被觸發
這裏是我的代碼:
final MaterialBetterSpinner materialDesignSpinner = (MaterialBetterSpinner)
findViewById(R.id.states_list);
ArrayAdapter<String> stateArrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.oman_states));
materialDesignSpinner.setAdapter(stateArrayAdapter);
materialDesignSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
System.out.println("works");
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
System.out.println()
不執行
什麼我錯在這裏做什麼?
可能是你的MaterialBetterSpinner正在捕捉OnItemSelectedListener –
我已經運行你的代碼,它工作得很好。 – RameshJaga
@Behrouz我認爲你的MaterialBetterSpinner自定義類擴展了OnItemClickListener,因此在那裏捕獲了點擊事件。所以它不會被setOnItemSelectedListener調用。所以檢查那個自定義類。 – RameshJaga