1.contacts联系人的数据的显示是个非常麻烦的事情,有很多的细节,但是我感觉这些天学习的东西基本就是这么几点,只是我从未认真地、低下头去思考,所以就不会啦!
(1)public void readRawContacts() {
ContentResolver resolver = getContext().getContentResolver();
Cursor c = resolver.query(ContactsContract.RawContacts.CONTENT_URI,
new String[] { "_id", ContactsContract.Contacts.DISPLAY_NAME, "phonebook_label" },
null, null, null);
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex("_id"));
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String phonebook_label = c.getString(c.getColumnIndex("phonebook_label"));
System.out.println(id + "---" + name + "-----" + phonebook_label);
}
}
//注意这里的(ContactsContract.Contacts.DISPLAY_NAME),不能像(”_id“)一样换成“display_name”,其他的都可以;
2、页面显示private void initData() {
Cursor c = contentResolver.query(Uri.parse(URL), new String[] {
"userid as _id", "username", "userpass", "userphone" }, null,
null, "userid desc");
adapter = new SimpleCursorAdapter(this, R.layout.list_item_user, c,
new String[] { "username", "userpass" }, new int[] {
R.id.tv_name, R.id.tv_phone },
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
lv_users.setAdapter(adapter);
}
//这个是在页面上显示数据的操作,但是我居然不会用,想不起来,唉,悲哀啊!
3、等,联系人数据库很复杂,值得研究