Android examples for android.widget:Spinner
Set the spinners selected item to match the provided value.
import android.widget.Spinner; public class Main { /**/*from w w w . j av a 2 s. com*/ * Set the spinners selected item to match the provided value. * * @param spinner * The spinner to be set. * @param arrayResource * The ID of the array values. * @param value * The value to set. */ public static void setSpinnerSelection(Spinner spinner, int arrayResource, Object value) { String positions[] = spinner.getResources().getStringArray(arrayResource); for (int i = 1; i < positions.length; i++) { if (positions[i].equals(value)) { spinner.setSelection(i); break; } } } }