Addev
Addev

Reputation: 32233

Change a Spinner programmatically in Android

Im trying to add a Spinner in my app configuration Activity. The spinner offers an option and save it persistently with SharedPreferences.

How can I set the spinner in a position programmatically (for init in the activity creation) Thanks in advance

Upvotes: 0

Views: 1760

Answers (1)

Luis Miguel Serrano
Luis Miguel Serrano

Reputation: 5099

To programatically set the spinner position you should use the method:

setSelection(position_to_select)

From the Spinner class (Actually the method's implementation is from the android.widget.AbsSpinner but it is inherited by Spinner class.

You can check the API documentation for it here: http://developer.android.com/reference/android/widget/Spinner.html

Upvotes: 1

Related Questions