All,
Just picked up the android 2.2 sdk and thought I would give it a run. I am
doing the hello world demo by Dan Morrel on youtube and then porting to 2.2
. I can't seem to figure out how to get from the cursor to the intent when
selecting a contact from the screen because the phone number is in a
different table? Any clues would be appreciated. Thanks, Jonathan
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);
}
}
--
"If men were angels, no government would be necessary."
--Madison
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en