Convenience method to set the spinners elements. - Android User Interface

Android examples for User Interface:Spinner

Description

Convenience method to set the spinners elements.

Demo Code


//package com.java2s;
import android.app.Activity;

import android.widget.ArrayAdapter;

import android.widget.Spinner;

public class Main {
    /**/*from  w  w  w  . ja  v  a 2  s  . c  om*/
     * Convenience method to set the spinners elements.
     *
     * @param activity The activity that contains the spinner.
     * @param spinner  The actual spinner
     * @param array The string array resource Id.
     */
    public static void setSpinnerElements(Activity activity,
            Spinner spinner, int array) {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter
                .createFromResource(activity, array,
                        android.R.layout.simple_spinner_dropdown_item);
        // Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        spinner.setAdapter(adapter);
    }
}

Related Tutorials