set Spinner Elements - Android android.widget

Android examples for android.widget:Spinner

Description

set Spinner Elements

Demo Code

import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class Main {

  /**/*from  ww w.  jav  a2s . c o m*/
   * 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