init ListView ArrayAdapter - Android User Interface

Android examples for User Interface:ListView

Description

init ListView ArrayAdapter

Demo Code

/*//from   w  w  w . j a va2  s. c  o  m
 * #%L
 * SlidingMenuDemo
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2012 Paul Grime
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
//package com.java2s;
import android.content.Context;

import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Main {
    public static void initListView(Context context, ListView listView,
            String prefix, int numItems, int layout) {
        // By using setAdapter method in listview we an add string array in list.
        String[] arr = new String[numItems];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = prefix + (i + 1);
        }
        listView.setAdapter(new ArrayAdapter<String>(context, layout, arr));
    }
}

Related Tutorials