Skip to content

Instantly share code, notes, and snippets.

@realdadfish
Created December 11, 2013 13:44
Show Gist options
  • Save realdadfish/7910659 to your computer and use it in GitHub Desktop.
Save realdadfish/7910659 to your computer and use it in GitHub Desktop.
Idiom to preselect an item in an Android `Spinner` widget without firing its `OnItemSelectedListener` right away. Unfortunately the notification of item selection changes happens asynchronously and also the check whether a listener exists _at all_ is only executed the next time the main loop has time to process the `View`'s request to process th…
final Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setSelection(2);
spinner.post(new Runnable() {
@Override
public void run() {
spinner.setOnItemSelectedListener(new OnItemSelectedListener() { ... });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment