0

我目前正在创建一个使用联系人数据的自动完成文本视图。我似乎无法修复最后一行的错误

    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    nameList = new ArrayList<String>(); 
    while (cur.moveToNext())
    {
        nameList.add(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
        nameList.add(cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
    }

    phonenumber =(AutoCompleteTextView) this.findViewById(R.id.tosend1);

错误行是这样的:

  ArrayAdapter<String> adapter = newArrayAdapter <String>(this,R.layout.list_item2,nameList);

好像有什么问题??

4

1 回答 1

1

查看 logcat 错误确实很有帮助,但我发现了几个错误,我只能猜测其余的:

Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
        new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }, 
        null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);

int nameIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

List<String> list = new ArrayList<String>();
while(cursor.moveToNext()) {
    list.add(cursor.getString(nameColumn) + ": " + cursor.getString(numberColumn));
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);

瞧,你的每个名字和联系人中的号码。

于 2012-05-07T23:37:50.183 回答