Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.List; import android.content.Context; import android.widget.ArrayAdapter; public class Main { /** * Creates a standard Android spinner adapter. Input items can be of any type. * * @param context Context with which to create the adapter * @param items List of items to populate the adapter with * @return The created adapter */ public static <E> ArrayAdapter<E> createSpinnerAdapter(Context context, List<E> items) { ArrayAdapter<E> adapter = createAdapter(context, android.R.layout.select_dialog_item, items); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); return adapter; } /** * Creates a standard Android spinner adapter. Input items can be of any type. * * @param context Context with which to create the adapter * @param items Array of items to populate the adapter with * @return The created adapter */ public static <E> ArrayAdapter<E> createSpinnerAdapter(Context context, E[] items) { return createSpinnerAdapter(context, Arrays.asList(items)); } /** * Creates a standard Android adapter. Input items can be of any type. * * @param context Context with which to create the adapter * @param layoutId Android resource id to be used for a list row * @param items List of items to populate the adapter with * @return The created adapter */ public static <E> ArrayAdapter<E> createAdapter(Context context, int layoutId, List<E> items) { return new ArrayAdapter<E>(context, layoutId, items); } }