0

我想从edittext中的选定联系人获取所有电话号码。我的问题是 edittext 只显示该选定联系人的第一个电话号码。假设一个联系人有两个号码,如 12345 和 00001。我的编辑文本只显示第一个号码 12345,但我想要 12345,00001。

我正在尝试这个:

    Cursor cursor = null; 
    String phoneNumber = "";
    int phoneIdx = 0;
    Uri result = data.getData();

    String id = result.getLastPathSegment();
    cursor = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id }, null); 
    phoneIdx = cursor.getColumnIndex(Phone.DATA);
    if (cursor.moveToFirst()) {
        phoneNumber = cursor.getString(phoneIdx);
        cursor.moveToNext();
    }
    else {

    }  
} 
finally {  
    if (cursor != null) {  
        cursor.close();
    }
    final EditText phoneInput = (EditText) findViewById(R.id.contact_phone);
    nameEntry.setText(phoneNumber);
}  
4

1 回答 1

0

    cursor.moveToFirst();
    while (cursor.isAfterLast() != true) {
        if (phoneNumber.equals("")) {
            phoneNumber = cursor.getString(phoneIdx);
        }

        else {
            phoneNumber = phoneNumber + "," + cursor.getString(phoneIdx);   
        }
        cursor.moveToNext();

     }

代替

if (cursor.moveToFirst()) {
                phoneNumber = cursor.getString(phoneIdx);
                    cursor.moveToNext();


            }
于 2013-10-19T17:49:55.663 回答