Skip to content
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

SetSelection not working. #129

Open
sleroy18 opened this issue Apr 25, 2018 · 3 comments
Open

SetSelection not working. #129

sleroy18 opened this issue Apr 25, 2018 · 3 comments

Comments

@sleroy18
Copy link

`ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, testArr);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
isBuying.setAdapter(adapter);
isBuying.setSelection(1);
`
will not work but the regular spinner

`isRenting = findViewById(R.id.rentingSpinner);

isRenting.setAdapter(adapterYesNo);
isRenting.setSelection(1);`

does work
The material spinner is set up correctly in the layout file. There is a hint associated with both spinners. The material spinner stays at the "hint" selection where the regular spinner is set to "No" which is position 1 in the array. I know I am using an array-string resource only for the regular spinner and I am converting that resource to an actual array for the material spinner.

Nothing I try seems to work.

Is there a work-around for setting the position in these "material spinners" it is not just this use of it, it is all!

@sleroy18
Copy link
Author

sleroy18 commented Apr 25, 2018

**** UPDATE*****
As a last ditch effort I went to set the text instead realizing that this was not a traditional spinner. The workaround I found to pre-set the selection is to use the adapter to get the text at position X and then set that text to the "spinners".

I still wish there was some functionality that did this already or better yet something much more clean.

@museady
Copy link

museady commented Sep 24, 2018

How did you set the selection on the spinner exactly ?

@kevinMartellotti
Copy link

For me the solution was to put the variable you want it to initialize to as the text programatically: spinner.setText(yourVariable; . Then add an onclick Listener to the spinner and match your variable to the spinner spinner.setOnItemClickListener((parent, view1, position, id) -> yourVariable=yourArray[position]);
Then if you wanna upload it to a a database, for example, use that variable as the uploaded, one, as getting the spinnerText will give you the first, even tho you put see it like the third maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants