package com.yarin.android.Examples_03_02;import android.app.Activity;import android.content.ContentResolver;import android.database.Cursor;import android.os.Bundle;import android.provider.ContactsContract;import android.provider.ContactsContract.PhoneLookup;import android.widget.EditText;import android.widget.TextView;public class Activity01 extends Activity {public void onCreate(Bundle savedInstanceState) {EditText Edit = new EditText(this);String string = "";super.onCreate(savedInstanceState);// 得到ContentResolver对象ContentResolver cr = getContentResolver();// 取得电话本中开始一项的光标Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null,null, null, null);// 向下移动一下光标while (cursor.moveToNext()) {// 取得联系人名字int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);String contact = cursor.getString(nameFieldColumnIndex);// 取得电话号码String ContactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "="+ ContactId, null, null);while (phone.moveToNext()) {String PhoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));string += (contact + ":" + PhoneNumber + "\n");}}cursor.close();// 设置TextView显示的内容Edit.setText(string);// 显示到屏幕setContentView(Edit);}}

更多相关文章

  1. Android设置文本框单行多行显示
  2. android ViewFlipper
  3. Android在Button按钮上同时显示文字和图片
  4. android核心技术之性能分析工具Systrace
  5. ANDROID视图空间代码
  6. android的ListView显示
  7. Android(安卓)EditView属性详细介绍
  8. android EditText彻底搞定输入框隐藏/显示背景 可编辑输入问题
  9. Android之Adapter用法总结

随机推荐

  1. 学会java基础能找工作吗?
  2. MySQL系列-InnoDB索引优化AHI、Change bu
  3. MySQL系列-InnoDB核心特性之事务介绍
  4. thinkPHP6框架基础知识
  5. 为什么考华为认证考华为认证有什么用?
  6. 华为认证改名HCNP改为HCIP
  7. 3.15 安装使用外部SQL Server的vCenter S
  8. KubeNode:阿里巴巴云原生容器基础设施运维
  9. IP网络性能测试工具——Renix Perf
  10. 华为认证考试题型分析备考指南