I am experiencing a odd problem. My OnItemSelectedListener seems only works one time, i mean that it shows my test Toast at the first time when clicking the coresponding items, but it doesn’t show the test Toast when i hit the same item at the second time.( it does work when clicking a different item at the second time) What is the problem? plz help me
partial code is here
//get task object from menu
taskListArr = new ArrayList<Task>();
taskListArr = getCurrentTasks(taskListArr);
myTask=new TaskListAdapter(this, 0, taskListArr);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, TaskModel.sorts);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sortSpinner.setAdapter(aa);
sortSpinner.setOnItemSelectedListener(this);
@SuppressWarnings("unchecked")
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if(arg2 == 0){
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
Collections.sort(taskListArr);
taskListView.setAdapter(myTask);
}
if(arg2 == 1){
Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
Collections.sort(taskListArr, new DateComparator());
taskListView.setAdapter(myTask);
}
if(arg2 == 2){
Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_SHORT).show();
Collections.sort(taskListArr, new PriorityComparator());
taskListView.setAdapter(myTask);
}
position = arg2;
}
public void onNothingSelected(AdapterView<?> arg0) {
}
Check out spinner in android developers site http://developer.android.com/reference/android/widget/Spinner.html
It selects one child at a time. So Selecting the already selected child again will not invoke onItemSelected function.