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
          主站蜘蛛池模板: 通河县| 安国市| 清流县| 普宁市| 耒阳市| 香河县| 长寿区| 浦北县| 山阴县| 津市市| 兴义市| 古浪县| 邵阳市| 泰兴市| 阿城市| 富锦市| 安福县| 新安县| 贵溪市| 崇礼县| 保山市| 莲花县| 霍林郭勒市| 龙山县| 岳阳县| 洪洞县| 衡山县| 和田县| 东平县| 通州区| 韶山市| 江达县| 淮南市| 花垣县| 元谋县| 板桥市| 东阿县| 资溪县| 德州市| 芦溪县| 寿光市|