Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8073733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:25:38+00:00 2026-06-05T14:25:38+00:00

The code I am using will display the Name and Number in the listview,

  • 0

The code I am using will display the Name and Number in the listview, but I need to display the Email also, for that I added some code snippet but Email didn’t display in the listview. I am using Android 2.1 platform.

CODE

 public class Trial2 extends Activity {
/** Called when the activity is first created. */
private static final int CONTACT_PICKER_RESULT = 1001; 
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

       Button Btn = (Button)findViewById(R.id.button1);
        Btn.setOnClickListener(new View.OnClickListener() { 

            @Override 
            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
                startActivityForResult(i, CONTACT_PICKER_RESULT);

            } 
        });
    }

    protected void onActivityResult(int reqCode, int resultCode, Intent data) { 
        super.onActivityResult(reqCode, resultCode, data);
        if(resultCode == RESULT_OK) {
            switch (reqCode) {
            case CONTACT_PICKER_RESULT:
                Cursor cursor = null;
                Cursor Emails = null;
                String number = "";
                String mailid;
                try {

                    Uri result = data.getData();

                    //get the id from the uri
                    String id = result.getLastPathSegment();  

                    //query
                    cursor = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone._ID + " = ? " , new String[] {id}, null);


                    int numberIdx = cursor.getColumnIndex(Phone.DATA);  

                    if(cursor.moveToFirst()) {
                        number = cursor.getString(numberIdx);

                    } else {

                    }

                     Emails = getContentResolver().query(Email.CONTENT_URI,null,Email.CONTACT_ID + " = " + id, null, null);

                     int emailid = Emails.getColumnIndex(Email.DATA);

                     if(Emails.moveToFirst()){

                         mailid =Emails.getString(emailid);
                     }else {

                    }



                } catch (Exception e) {
                    //failed 
                } finally {
                    if (cursor!=null) {
                        cursor.close();
                    }


                }

            }
        }
    }
}

Xml file

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

  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Trial2" />



</LinearLayout>

Solution ? Please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:25:39+00:00Added an answer on June 5, 2026 at 2:25 pm

    Try this code snippet to display your Email in listview.This will be helpful

    Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
                           null,ContactsContract.CommonDataKinds.Email.CONTACT_ID
                           + " = ?", new String[]{id}, null); 
    
    while (emailCur.moveToNext()) { 
    
    String email = emailCur.getString(
                  emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
    String emailType = emailCur.getString(
                  emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 
    }     emailCur.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using android 2.1 platform.The code I have will display the Name number
i am generating *.reg file using code which will have some important data. and
I'm using this code, from the nerddinner example. This method will display a list
I'm indexing and searching code using a custom analyzer. Given text will wi-fi work,
Will using GetComInterfaceForObject and passing the returned IntPtr to unmanaged code keep the managed
I'm using a code which will upload an image, put the image in the
I am using php code to query to a database and the results will
I'm using the following code which will generate a wav file which contains a
What will work faster - using PEAR package or require Some_Library.php files in code?
I am trying to write a simple tool using Shoes. This will indent code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.