Reputation: 1907
I have a Spinner that selects different commands to be run. I would like to programmatically simulate the user selecting a command (and running it).
Is this possible? Can it be done both visibly and invisibly (without showing the Spinner drop down and the simulated finger touch to select the command)?
Upvotes: 0
Views: 295
Reputation: 7121
As I said, you can call Spinner.setSelection(int position)
to invisibly select an item
To visibly select it, you can try calling spinner.performClick()
which should open the dropdown, then call spinner.setSelection(index)
. If dropdown is still opened after that you can try calling your activity's onBackPressed()
to close it.
Upvotes: 1