FileDocCategorySizeDatePackage
List7.javaAPI DocAndroid 1.5 API3014Wed May 06 22:41:08 BST 2009com.example.android.apis.view

List7

public class List7 extends android.app.ListActivity implements android.widget.AdapterView.OnItemSelectedListener
A list view example where the data comes from a cursor.

Fields Summary
private static String[]
PROJECTION
private int
mPhoneColumnIndex
private android.widget.TextView
mPhone
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_7);
        mPhone = (TextView) findViewById(R.id.phone);
        getListView().setOnItemSelectedListener(this);

        // Get a cursor with all people
        Cursor c = getContentResolver().query(People.CONTENT_URI, PROJECTION, null, null, null);
        startManagingCursor(c);
        mPhoneColumnIndex = c.getColumnIndex(People.NUMBER);

        ListAdapter adapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_1, // Use a template
                                                        // that displays a
                                                        // text view
                c, // Give the cursor to the list adatper
                new String[] {People.NAME}, // Map the NAME column in the
                                            // people database to...
                new int[] {android.R.id.text1}); // The "text1" view defined in
                                            // the XML template
        setListAdapter(adapter);
    
public voidonItemSelected(android.widget.AdapterView parent, android.view.View v, int position, long id)

        if (position >= 0) {
            Cursor c = (Cursor) parent.getItemAtPosition(position);
            mPhone.setText(c.getString(mPhoneColumnIndex));
        }
    
public voidonNothingSelected(android.widget.AdapterView parent)

        mPhone.setText(R.string.list_7_nothing);