Activity 代码如下:

/** Copyright (C) 2009 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package com.example.android.apis.app;import com.example.android.apis.R;import android.app.ListActivity;
import android.content.Context;
import android.database.CharArrayBuffer;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.view.View;
import android.view.ViewGroup;
import android.widget.QuickContactBadge;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;public class QuickContactsDemo extends ListActivity {static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {Contacts._ID, // 0Contacts.DISPLAY_NAME, // 1Contacts.STARRED, // 2Contacts.TIMES_CONTACTED, // 3Contacts.CONTACT_PRESENCE, // 4Contacts.PHOTO_ID, // 5Contacts.LOOKUP_KEY, // 6Contacts.HAS_PHONE_NUMBER, // 7};static final int SUMMARY_ID_COLUMN_INDEX = 0;static final int SUMMARY_NAME_COLUMN_INDEX = 1;static final int SUMMARY_STARRED_COLUMN_INDEX = 2;static final int SUMMARY_TIMES_CONTACTED_COLUMN_INDEX = 3;static final int SUMMARY_PRESENCE_STATUS_COLUMN_INDEX = 4;static final int SUMMARY_PHOTO_ID_COLUMN_INDEX = 5;static final int SUMMARY_LOOKUP_KEY = 6;static final int SUMMARY_HAS_PHONE_COLUMN_INDEX = 7;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("+ Contacts.HAS_PHONE_NUMBER + "=1) AND ("+ Contacts.DISPLAY_NAME + " != '' ))";Cursor c =getContentResolver().query(Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select,null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");startManagingCursor(c);ContactListItemAdapter adapter = new ContactListItemAdapter(this, R.layout.quick_contacts, c);setListAdapter(adapter);}private final class ContactListItemAdapter extends ResourceCursorAdapter {public ContactListItemAdapter(Context context, int layout, Cursor c) {super(context, layout, c);}@Overridepublic void bindView(View view, Context context, Cursor cursor) {final ContactListItemCache cache = (ContactListItemCache) view.getTag();// Set the namecursor.copyStringToBuffer(SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer);int size = cache.nameBuffer.sizeCopied;cache.nameView.setText(cache.nameBuffer.data, 0, size);final long contactId = cursor.getLong(SUMMARY_ID_COLUMN_INDEX);final String lookupKey = cursor.getString(SUMMARY_LOOKUP_KEY);cache.photoView.assignContactUri(Contacts.getLookupUri(contactId, lookupKey));}@Overridepublic View newView(Context context, Cursor cursor, ViewGroup parent) {View view = super.newView(context, cursor, parent);ContactListItemCache cache = new ContactListItemCache();cache.nameView = (TextView) view.findViewById(R.id.name);cache.photoView = (QuickContactBadge) view.findViewById(R.id.badge);view.setTag(cache);return view;}}final static class ContactListItemCache {public TextView nameView;public QuickContactBadge photoView;public CharArrayBuffer nameBuffer = new CharArrayBuffer(128);}
}

  

布局界面如下:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source ProjectLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
--><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:paddingLeft="0dip"android:paddingRight="9dip"android:layout_height= "wrap_content"android:minHeight="48dip"><QuickContactBadgeandroid:id="@+id/badge"android:layout_marginLeft="2dip"android:layout_marginRight="14dip"android:layout_marginTop="4dip"android:layout_marginBottom="3dip"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:layout_height= "wrap_content"android:layout_width= "wrap_content"android:src="@drawable/alert_dialog_icon"style="?android:attr/quickContactBadgeStyleWindowSmall" /><TextViewandroid:id="@+id/name"android:textAppearance="?android:attr/textAppearanceMedium"android:paddingLeft="2dip"android:layout_centerVertical="true"android:layout_toRightOf="@id/badge"android:layout_width="match_parent"android:layout_height="wrap_content" /></RelativeLayout>

  

Android 快速选择联系人相关推荐

  1. Android系统联系人全特效实现(下),字母表快速滚动

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9050671 在上一篇文章中,我和大家一起实现了类似于Android系统联系人的分组 ...

  2. Android系统联系人全特效实现(上),分组导航和挤压动画

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9033553 记得在我刚接触Android的时候对系统联系人中的特效很感兴趣,它会根 ...

  3. Android读取联系人的姓名及电话号码

    Android中联系人的信息是通过ContentProvider来供外部应用获取的,我们使用时只需根据系统联系人ContentProvider的Uri即可获取所需数据.下面讲解如何获取联系人的姓名及电 ...

  4. Android VCard联系人备份恢复(导入/导出)详解

    原文地址为: Android VCard联系人备份恢复(导入/导出)详解 首先我们简单的看下在Android中联系人的存储结构. 工作环境:android 2.3.3 联系人的主要数据存放在raw_c ...

  5. android+头像+程序,Android获取联系人头像的方法

    本文实例讲述了Android获取联系人头像的方法.分享给大家供大家参考,具体如下: public byte[] getPhoto(String people_id) { String photo_id ...

  6. Android系统设置联系人头像教程

    为什么80%的码农都做不了架构师?>>>    Android系统的手机是不支持编辑SIM卡上的联系人的,所以要设置联系人的头像也是没办法的,那么要怎么才能设置Android系统的联 ...

  7. android 联系人 中文 排序,Android中文联系人排序及检索补丁的原理

    Android中文联系人排序及检索补丁的原理(090819更新) 2009年4月26日,更新了源码和相关文件 很久以前做了这个补丁,有幸的是朋友们都还算喜爱它,没白费功夫.不少朋友来信问它的原理,现在 ...

  8. Android中文联系人排序及检索补丁的原理(090819更新)

    原文转自孙志岗老师Sunner的博客:http://blog.sunner.cn/2009/04/android_pinyin_sorting/ 文章写的是针对Android1.0, 1.1及1.5( ...

  9. Android手机联系人URI总结

    Android手机联系人URI总结 参考来自:https://wenku.baidu.com/view/d28a2e6b2d3f5727a5e9856a561252d380eb20b2.html An ...

最新文章

  1. 2021年大数据Flink(三十三):​​​​​​​Table与SQL相关概念
  2. 最新!中国内地高校ESI排名出炉:342所大学上榜
  3. python核心编程学习(第四章)
  4. 基于NPOI的Excel数据导入
  5. java什么是函数式编程,Java 函数式编程(一)初识篇
  6. java io字符输出流_Java字符输入输出流
  7. 深入理解闭包系列第二篇——从执行环境角度看闭包
  8. 简述python的编程规范_python编程规范
  9. C语言为何到现在都是热门语言?原因很简单,程序员大牛都知道
  10. notepad++以16进制查看文件
  11. Ubuntu中Python3找不到_sqlite3模块
  12. html5 retina 1像素,走向视网膜(Retina)的Web时代
  13. 数组的几个重要方法以及如何清空数组
  14. UTC和GMT时间区别
  15. 装系统时的UEFI模式
  16. 深度学习笔记--pytorch从梯度下降到反向传播BP到线性回归实现,以及API调用和手写数据集的实现
  17. APISpace 迎国庆
  18. Android系统USB读卡器
  19. vivos9开启定位服务设置步骤介绍(图文教程)
  20. 要么到岗,要么离职!马斯克:特斯拉「远程办公」到此结束

热门文章

  1. ASP.net本地调试时正常,发布时错误的几个问题解析
  2. VIM中空格和TAB的替换 [转]
  3. 用tabbar mode为Emacs建立ta
  4. eclipse team 没有svn
  5. Python 文件操作二
  6. 使用CSS如何解决inline-block元素的空白间距
  7. TCP: time wait bucket table overflow解决方法
  8. TP id 对字符串的查找
  9. 电路图中常用的英文缩写的中文解释
  10. Shader 中的随机与噪声