pakorn
11-12-2008, 07:54 PM
I can't retrieve the data, such as user names and phone numbers, fron the contact lists on Android. Here is my source code.
public void onClick (View view){
String[] projection = new String[] {
People.NAME,
People.NUMBER,
};
temp = number.getText().toString();
// Uri myPerson = Uri.parse("content://contacts/people");
// Uri myPerson = Contacts.People.CONTENT_URI;
// Cursor managedCursor = managedQuery(myPerson, null, null, null, null);
Cursor c = getContentResolver().query(People.CONTENT_URI, projection, null, null,
null);
startManagingCursor(c);
output.setText("check");
String[] test = getColumnData (c);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, test));
}
private String[] getColumnData(Cursor cur){
int i = 0;
String[] result = null;
if (cur.moveToFirst()) {
String namex;
String phoneNumberx;
int nameColumn = cur.getColumnIndex(People.NAME);
int phoneColumn = cur.getColumnIndex(People.NUMBER);
String imagePath;
do {
// Get the field values
namex = cur.getString(nameColumn);
phoneNumberx = cur.getString(phoneColumn);
// result[i] = namex;
// i++;
// if (phoneNumberx == temp)
// {
// temp9 = namex;
// temp10 = phoneNumberx;
// break;
// }
// Do something with the values.
} while (cur.moveToNext());
}
return (result);
}
}
public void onClick (View view){
String[] projection = new String[] {
People.NAME,
People.NUMBER,
};
temp = number.getText().toString();
// Uri myPerson = Uri.parse("content://contacts/people");
// Uri myPerson = Contacts.People.CONTENT_URI;
// Cursor managedCursor = managedQuery(myPerson, null, null, null, null);
Cursor c = getContentResolver().query(People.CONTENT_URI, projection, null, null,
null);
startManagingCursor(c);
output.setText("check");
String[] test = getColumnData (c);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, test));
}
private String[] getColumnData(Cursor cur){
int i = 0;
String[] result = null;
if (cur.moveToFirst()) {
String namex;
String phoneNumberx;
int nameColumn = cur.getColumnIndex(People.NAME);
int phoneColumn = cur.getColumnIndex(People.NUMBER);
String imagePath;
do {
// Get the field values
namex = cur.getString(nameColumn);
phoneNumberx = cur.getString(phoneColumn);
// result[i] = namex;
// i++;
// if (phoneNumberx == temp)
// {
// temp9 = namex;
// temp10 = phoneNumberx;
// break;
// }
// Do something with the values.
} while (cur.moveToNext());
}
return (result);
}
}