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 
17 package android.widget.listview;
18 
19 import android.app.ListActivity;
20 import android.content.Intent;
21 import android.database.Cursor;
22 import android.os.Bundle;
23 import android.provider.Contacts.People;
24 import android.provider.Settings;
25 import android.view.View;
26 import android.widget.AdapterView;
27 import android.widget.AdapterView.OnItemClickListener;
28 import android.widget.ListAdapter;
29 import android.widget.SimpleCursorAdapter;
30 
31 public class ListManagedCursor extends ListActivity implements OnItemClickListener {
32 
33     @Override
onCreate(Bundle savedInstanceState)34     protected void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36 
37         // Get a cursor with all people
38         Cursor c = getContentResolver().query(Settings.System.CONTENT_URI, null, null, null, null);
39         startManagingCursor(c);
40 
41         ListAdapter adapter = new SimpleCursorAdapter(this,
42                 // Use a template that displays a text view
43                 android.R.layout.simple_list_item_1,
44                 // Give the cursor to the list adatper
45                 c,
46                 // Map the NAME column in the people database to...
47                 new String[] {People.NAME} ,
48                 // The "text1" view defined in the XML template
49                 new int[] {android.R.id.text1});
50         setListAdapter(adapter);
51         getListView().setOnItemClickListener(this);
52     }
53 
onItemClick(AdapterView parent, View view, int position, long id)54     public void onItemClick(AdapterView parent, View view, int position, long id) {
55         Intent dummyIntent = new Intent(this, ListSimple.class);
56         startActivity(dummyIntent);
57     }
58 }
59 
60