package app.test;
import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class Test extends ListActivity implements OnItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView lv = getListView();
Cursor c = managedQuery(People.CONTENT_URI, null, null, null,
People.NAME);
String[] cols = new String[] { People.NAME };
int[] views = new int[] { android.R.id.text1 };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, c, cols, views);
this.setListAdapter(adapter);
lv.setOnItemClickListener(this);
}
public void onItemClick(AdapterView> adView, View target, int position,
long id) {
Log.v("ListViewActivity", ((TextView) target).getText()
+ ". Position = " + position + ". Id = " + id);
Uri selectedPerson = ContentUris.withAppendedId(People.CONTENT_URI, id);
Intent intent = new Intent(Intent.ACTION_VIEW, selectedPerson);
startActivity(intent);
}
}