首页 > 叽歪生活 > 使用ListView获取android联系人信息

使用ListView获取android联系人信息

本文作为一个小笔记记下,站长刚开始学习Android,具体的原因还没有搞清除。就直接贴代码了:

main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 
 <ListView
 android:id="@+id/myListView"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 />
 
</LinearLayout>

主Activity的代码:

 

ListView myListView = (ListView)findViewById(R.id.myListView);
 
 Cursor cur = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
 null, null, null, null);
 Log.i(TAG, "获取数据库Phones的Cursor成功");
 startManagingCursor(cur);
 
 //ListAdapter是ListView和后台数据的桥梁
 ListAdapter adapter = new SimpleCursorAdapter(this,
 android.R.layout.simple_list_item_2,
 cur,
 new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
 , ContactsContract.CommonDataKinds.Phone.NUMBER},
 new int[] {android.R.id.text1, android.R.id.text2}
 );
 myListView.setAdapter(adapter);

运行结果如图所示:

有关讨论:

http://www.eoeandroid.com/thread-53384-1-1.html

 

 

转载请标明出处:萝卜根

原文地址请标明:原文地址

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
*

:yund: :yun: :yes: :xiaxia: :xiaom: :xiaohan: :wuyu: :wuxiao: :woshou: :woquan: :wink: :tiaodou: :tiaod: :sikao: :pa: :oops: :ok: :no: :mad: :lihai: :leihua: :lei: :ku: :konghe: :kbu: :jiwai: :jiong: :jiay: :huo: :huaixiao: :hanxiao: :han: :haha: :guolai: :guan: :guai: :ganga: :eek: :dou: :diao: :deng: :buli: :bizui: :bishi: :biggrin: :arrow: