nullim使用Cursor cursor = getContentResolver() .query(contactUri,projection,null,null,null);获取点击的联系人数量。是否可以使用此查询获取电子邮件,号码和名称。同时? 我们可以这样做吗?如下图所示?
String[] projection = {Phone.NUMBER};
String[] projection1 = {Email.DATA};
String[] projection2 = {Contacts.DISPLAY_NAME};
Cursor cursor = getContentResolver().
query(contactUri, projection, null,projection1,projection2);
cursor.moveToFirst();
int column = cursor.getColumnIndex(Phone.NUMBER);
int column1 = cursor.getColumnIndex(Email.DATA);
int column2= cursor.getColumnIndex(Contacts.DISPLAY_NAME);
String number = cursor.getString(column);
String email1 = cursor.getString(column1);
String name1 = cursor.getString(column2)
这可能吗?
现在这是正确的吗?
String[] projection = {Phone.NUMBER, Email.ADDRESS, Contacts.DISPLAY_NAME};
Cursor cursor = getContentResolver().
query(contactUri, projection, null,null,null);
cursor.moveToFirst();
int column = cursor.getColumnIndex(Phone.NUMBER);
int column1 = cursor.getColumnIndex(Email.ADDRESS);
int column2= cursor.getColumnIndex(Contacts.DISPLAY_NAME);
String number = cursor.getString(column);
String email1 = cursor.getString(column1);
String name1 = cursor.getString(column2)
editText3 = (EditText) findViewById(R.id.editText3);
editText17 = (EditText) findViewById(R.id.editText17);
editText3.setText(number);
editText17.setText(email1);
仅在文本框中设置了电话号码 edittext3和edittext17都有手机号码?我做错了什么? 谢谢
答案 0 :(得分:1)
您可以在数组中放置多个值:
String[] projection = {Phone.NUMBER, Email.DATA, Contacts.DISPLAY_NAME};
所有在一起:
String[] projection = {Phone.NUMBER, Email.DATA, Contacts.DISPLAY_NAME};
Cursor cursor = getContentResolver().query(contactUri, projection, null, null, null);
int column = cursor.getColumnIndex(Phone.NUMBER);
int column1 = cursor.getColumnIndex(Email.DATA);
int column2= cursor.getColumnIndex(Contacts.DISPLAY_NAME);
if(cursor.moveToFirst()) { // Check if data exists
String number = cursor.getString(column);
String email1 = cursor.getString(column1);
String name1 = cursor.getString(column2)
}