I have created a spinner which is automatically updated with appliance names when a person adds an appliance using an array adapter. I created an OnItemSelected method with
If you are trying to avoid the initial call to your listener's onItemSelected() method, another option is to use post() to take advantage of the view's message queue. The first time the spinner checks for your listener it won't be set yet.
// Set initial selection
spinner.setSelection(position);
// Post to avoid initial invocation
spinner.post(new Runnable() {
@Override public void run() {
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
// Only called when the user changes the selection
}
@Override
public void onNothingSelected(AdapterView> parent) {
}
});
}
});