这是我从设备中获取联系人姓名的代码。我遇到的问题是,在我的列表视图中,“元素”将显示联系人列表中的每个姓名。关于如何删除没有 SMS 的名称的任何想法?
// converts contacts from cursor to arraylist
nameList = new ArrayList<String>();
cursor = getContacts();
while(cursor.moveToNext()){
nameList.add(cursor.getString(cursor.getColumnIndex(
ContactsContract.Data.DISPLAY_NAME )));
}
// convert arraylist to string array
name = new String[nameList.size()];
name = nameList.toArray(name);
// new arraylist for after contacts with no messages are removed
elements = new ArrayList<String>();
//convert back to an arraylist
for(int i = 0; i < name.length; i++){
elements.add(name[i]);
}