2012-03-06 9 views
0

私はすべての電話帳の連絡先を取得してカスタムビューで自分のリストに表示するカスタムリストを作成しました。私はすべての連絡先(連絡先IDを含む)をarraylistに保存します。私がリストをクリックすると、デフォルトのアンドロイドの方法でその連絡先のすべての詳細を開くことができます。これが可能かどうかを教えてください。電話帳の連絡先を取得するカスタムリストから詳細ページを表示

私のコードは、私自身のリストの中の連絡先を保存するための以下の通りです:

arraylist = new ArrayList<PhoneBookUserEntity>(); 
    Cursor cursor = getContentResolver().query(
      ContactsContract.Contacts.CONTENT_URI, null, null, null, Phone.DISPLAY_NAME + " ASC"); 
    if (cursor.getCount() > 0) 
    { 
     while (cursor.moveToNext()) 
     { 

      PhoneBookUserEntity user = new PhoneBookUserEntity(); 
      // Pick out the ID, and the Display name of the 
      // contact from the current row of the cursor 
      user.setId(cursor.getString(cursor.getColumnIndex(BaseColumns._ID))); 
      user.setPhoneBookName(cursor.getString(cursor.getColumnIndex(
        ContactsContract.Contacts.DISPLAY_NAME))); 

      String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 
      // if (Boolean.parseBoolean(hasPhone)) { 
      Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ user.getId(), null, null); 
      while (phones.moveToNext()) { 
       user.sePhoneNumber(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));     
      } 
      phones.close(); 
      //} 
      // user.sePhoneNumber(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))); 

      Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + user.getId(), null, null); 
      while (emails.moveToNext()) { 
       // This would allow you get several email addresses 
       user.setEmailAddress(emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA))); 
      } 
      emails.close(); 
      user.setImageURI(getPhotoUri(user.getId())); 
      arraylist.add(user); 
      // Do something with the values you have, 
      // such as print them out or add to a list 
      //System.out.println("Current contact on this iteration is : " + name); 

      // This is where we query for Emails, Addresses etc 
      // Add snippets below into here, depending on what you need 
     } 

    } 
    cursor.close(); 
+1

で連絡先カードを開く必要があり、この

Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID)); intent.setData(uri); context.startActivity(intent); 

をお試しください同様の機能を実行するためのピッカー。 http://tutorials-android.blogspot.in/2011/11/how-to-call-android-contacts-list.html – Soham

+0

私のカスタムリストに連絡先があります。私は、ある人が連絡先をクリックして連絡先の詳細が表示されたときに、デフォルトのビューを開きたいとします。 – SoH

答えて

0

これはところで、あなたが連絡先を使用することができますアンドロイド

+0

androidruntimeexception: "アクティビティコンテキスト外からstartActivity()を呼び出すには、FLAG_ACTIVITY_NEW_TASKフラグが必要です。これは本当に必要なものですか?" 修正するには、次を挿入してください。 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); –

関連する問題