[List7.java]

public class List7 extends ListActivity implements OnItemSelectedListener {
    private static String[] PROJECTION = new String[] {
        People._ID, People.NAME, People.NUMBER
    };

    @Override
    protected void onCreate(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 void onItemSelected(AdapterView parent, View v, int position, long id) {
        if (position >= 0) {
            Cursor c = (Cursor) parent.getItemAtPosition(position);
            mPhone.setText(c.getString(mPhoneColumnIndex));
        }
    }

    public void onNothingSelected(AdapterView parent) {
        mPhone.setText(R.string.list_7_nothing);

    }

    private int mPhoneColumnIndex;
    private TextView mPhone;
}


[list_7.xml]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 android:paddingLeft="8dip"
 android:paddingRight="8dip">
 
 <ListView android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="0dip"
     android:layout_weight="1"
     android:drawSelectorOnTop="false"/>
    
    <TextView android:id="@+id/phone"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:background="@drawable/blue"/>
     
</LinearLayout>

'old > API_Demo' 카테고리의 다른 글

Views_Lists_Array(Overlay)  (0) 2010.04.27
Views_Lists_Photos  (0) 2010.04.27
Views_Lists_ListAdapter Collapsed  (0) 2010.04.27
Views_Lists_Separators  (0) 2010.04.27
Views_Lists_ListAdapter  (0) 2010.04.27
Posted by jazzlife
,