views:

26

answers:

0

package hello.android;

import android.app.ListActivity; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; //import android.provider.Contacts.People; //import android.provider.Contacts.Phones; import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.PhoneLookup;

import android.view.View; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleCursorAdapter;

public class hello extends ListActivity { /** Called when the activity is first created. */ private ListAdapter mAdapter;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // get access to some data from the content provider
    // in this case issue a query to get the entries list of contacts
    //Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
    Cursor c = getContentResolver().query(Contacts.CONTENT_URI, null, null, null, null);
    startManagingCursor(c);

    // create a mapping for the content provider from the data source
    // to the user interface
    //String[] columns = new String[] {People.NAME};
    String[] columns = new String[] {Contacts.DISPLAY_NAME};
    int[] names = new int[] {R.id.row_entry};

    // make a class that will make use of our mapping
    mAdapter = new SimpleCursorAdapter(this, R.layout.main, c, columns, names);

    // set to be our current adapter
    setListAdapter(mAdapter);
}

@Override
// the class that is called every time the user clicks something
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    // the reflections of a applications intent to perform some activity
    // in this case a call action to dial the phone
    Intent i = new Intent(Intent.ACTION_CALL);
    Cursor c = (Cursor) mAdapter.getItem(position);
    //long phoneId = c.getLong(c.getColumnIndex(People.PRIMARY_PHONE_ID));
    //i.setData(Phones.CONTENT_URI.addId(phoneId));

    // Causes the dialer to appear on the screen and initiate the phone call
    startActivity(i);
}

}