Android: setSelection having no effect on Spinner
Solution 1:
Try moving the call to setSelection()
after the call to setAdapter()
.
Solution 2:
I had similar problem. In my case setAdaper
and setSelection
were in correct order! Executed form onCreate
worked, but when executed from onResume
had no effect.
The solution is to call setSelection(my_pos, true)
. Notice the second parameter.
Solution 3:
You might try
mSpinner.post(new Runnable() {
public void run() {
mSpinner.setSelection(1);
}
});
this will post the runnable action to run as soon as the view is created
Solution 4:
In my case none of the answers worked, so I queued the setSelection through a Handler
new Handler().postDelayed(new Runnable() {
public void run() {
mSpinner.setSelection(1);
}
}, 100);
Doing this could cause problems when running on slow devices, but I'm working for a specific device so it's ok to use this hack