sunwei07

          Android入門 新手學習 開發

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            4 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

          public void onCreate(Bundle savedInstanceState)
           {
            TextView tv = new TextView(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);
                   //取得電話號碼
                   int numberFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);   
                   String number = cursor.getString(numberFieldColumnIndex);
                   
                   string += (contact+":"+number+"\n");
                  }
                  cursor.close();
            //設置TextView顯示的內容
            tv.setText(string);
            //顯示到屏幕
            setContentView(tv);
           }

          posted on 2011-02-15 11:26 sunwei_07 閱讀(358) 評論(0)  編輯  收藏 所屬分類: Android
          主站蜘蛛池模板: 安塞县| 平定县| 札达县| 台北市| 尖扎县| 民乐县| 洪江市| 五莲县| 横山县| 新津县| 陇西县| 宁城县| 东源县| 安龙县| 汶上县| 彭阳县| 奇台县| 大宁县| 克东县| 乾安县| 定州市| 保定市| 隆德县| 深圳市| 华安县| 彭水| 贺兰县| 南溪县| 应城市| 南康市| 阿荣旗| 广州市| 辛集市| 鹤庆县| 抚州市| 防城港市| 广昌县| 嘉鱼县| 策勒县| 灵寿县| 张家港市|