Creates a standard Android ListView multiple-choice adapter. - Android User Interface

Android examples for User Interface:ListView

Description

Creates a standard Android ListView multiple-choice adapter.

Demo Code


//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 multiple-choice 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> createMultipleListViewAdapter(
            Context context, List<E> items) {
        return createAdapter(context,
                android.R.layout.simple_list_item_multiple_choice, items);
    }

    /**
     * Creates a standard Android ListView multiple-choice 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> createMultipleListViewAdapter(
            Context context, E[] items) {
        return createMultipleListViewAdapter(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);
    }
}

Related Tutorials