Android Lists

This video, part of my Android Quick Code Access series of posts, explains Android Lists. It's from my course Learning Android App Programming.

The Java source code for this example is shown below...

// Copyright (C) 2007 The Android Open Source Project.

package com.example.android.apis.view;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

/**
 * A list view example where the 
 * data for the list comes from an array of strings.
 */
public class List1 extends ListActivity {

    // onCreate method executed when the ListActivity is started.
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Use an existing ListAdapter that will map an array
        // of strings to TextViews
        setListAdapter(new ArrayAdapter(this,
                android.R.layout.simple_list_item_1,
                mStrings));
        getListView().setTextFilterEnabled(true);
    }
    // String array containing items to be displayed.
    private String[] mStrings = Cheeses.sCheeseStrings;
}

For list item layout options (like android.R.layout.simple_list_item_1 used in the sample above), see the R.layout class.