我有一个OnItemSelectedListener
for my Spinner
,但是当所选项目与前一个项目相同时,它不会被调用。显然OnClickListener
不是 a 的选项Spinner
。每次用户单击某个项目时,我都需要捕捉。任何的想法?
也许这Spinner
是在ActionBar
扰乱正常行为的事实?
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.tracklist_menu, menu);
Spinner spinner = (Spinner) menu.findItem(R.id.option_ordering_spinner)
.getActionView();
spinner.setAdapter(mSpinnerAdapter);
spinner.setSelection(PrefsHelper.getOrderingSpinnerPos(prefs));
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String str = "selected";
System.out.println(str);
if (optionMenuInitialized) {
switch (position) {
case 0:
// rdm
getActivity()
.sendBroadcast(
new Intent(
MyIntentAction.DO_RESHUFFLE_PLAYLIST));
smp.setCurrentTracklistCursorPos(-1);
trackAdapter.notifyDataSetChanged();
break;
case 1:
// artist
getActivity()
.sendBroadcast(
new Intent(
MyIntentAction.DO_ORDER_PLAYLIST_BY_ARTIST));
smp.setCurrentTracklistCursorPos(-1);
trackAdapter.notifyDataSetChanged();
break;
case 2:
// folder
getActivity()
.sendBroadcast(
new Intent(
MyIntentAction.DO_ORDER_PLAYLIST_BY_FOLDER));
smp.setCurrentTracklistCursorPos(-1);
trackAdapter.notifyDataSetChanged();
break;
}
PrefsHelper.setOrderingSpinnerPos(prefEditor, position);
prefEditor.commit();
}
optionMenuInitialized = true;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}