Set the spinners selected item to match the provided value. - Android User Interface

Android examples for User Interface:Spinner

Description

Set the spinners selected item to match the provided value.

Demo Code


//package com.java2s;

import android.widget.Spinner;

public class Main {
    /**//from  www  .  j a va 2s .c  o  m
     * 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;
            }
        }
    }
}

Related Tutorials