1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.widget.listview;
18
19import android.app.ListActivity;
20import android.content.Intent;
21import android.database.Cursor;
22import android.os.Bundle;
23import android.provider.Settings;
24import android.provider.Contacts.People;
25import android.view.View;
26import android.widget.AdapterView;
27import android.widget.ListAdapter;
28import android.widget.SimpleCursorAdapter;
29import android.widget.AdapterView.OnItemClickListener;
30
31
32public class ListManagedCursor extends ListActivity implements OnItemClickListener {
33
34    @Override
35    protected void onCreate(Bundle savedInstanceState) {
36        super.onCreate(savedInstanceState);
37
38        // Get a cursor with all people
39        Cursor c = getContentResolver().query(Settings.System.CONTENT_URI, null, null, null, null);
40        startManagingCursor(c);
41
42        ListAdapter adapter = new SimpleCursorAdapter(this,
43                // Use a template that displays a text view
44                android.R.layout.simple_list_item_1,
45                // Give the cursor to the list adatper
46                c,
47                // Map the NAME column in the people database to...
48                new String[] {People.NAME} ,
49                // The "text1" view defined in the XML template
50                new int[] {android.R.id.text1});
51        setListAdapter(adapter);
52        getListView().setOnItemClickListener(this);
53    }
54
55    public void onItemClick(AdapterView parent, View view, int position, long id) {
56        Intent dummyIntent = new Intent(this, ListSimple.class);
57        startActivity(dummyIntent);
58    }
59}
60
61