-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selecting the first item programmatically #12
Comments
MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spinner);
spinner.setItems("Ice Cream Sandwich", "Jelly Bean", "KitKat", "Lollipop", "Marshmallow");
spinner.setSelectedIndex(1); // <--- Set the item programmatically
spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
@Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show();
}
});
spinner.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() {
@Override public void onNothingSelected(MaterialSpinner spinner) {
Snackbar.make(spinner, "Nothing selected", Snackbar.LENGTH_LONG).show();
}
}); |
The method setSelectedIndex just chooses the item to appear as the first item, but I would like to actually select the item as if it would call on onItemSelected. Thanks again, very nice spinner! |
You should just run whatever code is in your listener when you select the item. I don't know why this would be needed. If you really feel like this is necessary please provide an example. |
what he means is that when he use |
+1 |
How do you select the first item in the spinner?
I tried doing the following,
spinner.setOnItemListeners(..){ ... };
spinner.setSelectedIndex(2);
spinner.setSelected(true);
but it doesn't seem to be working.
Thanks!
The text was updated successfully, but these errors were encountered: