Accessing of the data is not proper?
<p>I am using android 2.1 platform.The code I have will display the Name number and email ID of all the persons from the Emulator contact list,by using this code I will get the requirement as on above.I have some contacts in my emulator, I created two more contacts (say C and D). BUT the issues are</p>

<p><strong>Issue 1.</strong> If I create a new contact having <strong>name and number not email</strong>, This contact will take the   <strong>email ID</strong> from the contact just down to it.<strong>for eg:</strong> if I create a name C has no email ID but D has email ID, D is the contact already in the Emulator.  <strong>C will take D's email ID</strong>.C and D have same email ID.</p>

<p><strong>Issue 2.</strong> If again I create a new contact having <strong>name email but not number</strong>, This contact will take the   <strong>number</strong> from the contact I previously created.<strong>for eg:</strong> if I create the name E has no number but it will take the number of the contact C. so <strong>C and E have the same number</strong> .</p>

<p>I am using this code </p>

<pre><code>public class GetAllDatas extends Activity {

ListView lvItem;
private Button btnAdd;
String displayName="", emailAddress="", phoneNumber="";
ArrayList&lt;String&gt; contactlist=new ArrayList&lt;String&gt;(); 
ArrayAdapter&lt;String&gt; itemAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    lvItem = (ListView)this.findViewById(R.id.lvitems); 
    btnAdd = (Button)this.findViewById(R.id.btnAddItem);

    itemAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,contactlist);
    lvItem.setAdapter(itemAdapter);

    btnAdd.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            readContacts();
        }
    });

} 

private void readContacts()
{
    ContentResolver cr =getContentResolver();
    Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    while (cursor.moveToNext()) 
    {
        displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));       
        String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));


        Cursor emails = cr.query(Email.CONTENT_URI,null,Email.CONTACT_ID + " = " + id, null, null);
        while (emails.moveToNext()) 
        { 
            emailAddress = emails.getString(emails.getColumnIndex(Email.DATA));
            break;
        }
        emails.close();


        if(Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0)
        {
            Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{id}, null);
            while (pCur.moveToNext()) 
            {
                 phoneNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                break;  
            } 
            pCur.close();
        }


        //  To display the Details
        contactlist.add(displayName+", "+phoneNumber+", "+ emailAddress+"\n");
        itemAdapter.notifyDataSetChanged();
    }
    Collections.sort(contactlist);
    cursor.close(); 
}
}
</code></pre>

<p>How can I solve this problem ?</p>
