Created
December 11, 2013 13:44
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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