我根据本教程创建了一个列表视图:
http://www.vogella.com/articles/AndroidListView/article.html
在那个链接中,我已经实现了
13> 在ListView中选择多个项目
我的列表视图工作正常。我通过使用以下代码填充电话联系人来自定义列表视图:
private List<Model> getModel()
{
List<Model> list = new ArrayList<Model>();
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0)
{
while (cur.moveToNext())
{
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
{
// This inner cursor is for contacts that have multiple numbers.
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
while (pCur.moveToNext())
{
list.add(get(name));
}
pCur.close();
}
}
}
cur.close();
return list;
}
现在会显示联系人的姓名,但未对它们进行排序。我该如何排序?
请帮忙!提前致谢!