Android examples for User Interface:ListView
Creates a standard Android ListView adapter.
//package com.java2s; import java.util.Arrays; import java.util.List; import android.content.Context; import android.widget.ArrayAdapter; public class Main { /**//from ww w .j a v a2 s . c o m * Creates a standard Android ListView 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> createListViewAdapter( Context context, List<E> items) { return createAdapter(context, android.R.layout.simple_list_item_1, items); } /** * Creates a standard Android ListView 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> createListViewAdapter( Context context, E[] items) { return createListViewAdapter(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); } }