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 8110179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:39:29+00:00 2026-06-06T01:39:29+00:00

I am using Android 2.1 platform, I have 7 contacts in my emulator when

  • 0

I am using Android 2.1 platform, I have 7 contacts in my emulator when I try to retrieve the email of the contacts it will be working but not in the order I saved in the contact List.If I created a new contact with new email,it will go to the last.I am using this code.

Code

public class RetrieveData extends Activity {

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


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   lvItem = (ListView)this.findViewById(R.id.listview);  
   btnAdd = (Button)this.findViewById(R.id.btn);
   itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,contactlist);
   lvItem.setAdapter(itemAdapter);
   btnAdd.setOnClickListener(new View.OnClickListener() {
       public void onClick(View v) {
           GetEmails();

       }
   }); 
}

private void GetEmails()
    {


    ContentResolver cr =getContentResolver();
    Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    while (cursor.moveToNext()) 
    {       
        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));
            contactlist.add(emailAddress);
            itemAdapter.notifyDataSetChanged();
        }
        emails.close();

    }
    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" >

<ListView
    android:id="@+id/listview"
    android:layout_width="fill_parent"
    android:layout_height="288dp"
    android:layout_weight="0.03" >

</ListView>

<Button
    android:id="@+id/btn"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:text="Retrieve"
    android:layout_weight="0.01"  />


</LinearLayout>

How to solve it ?

  • 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-06T01:39:30+00:00Added an answer on June 6, 2026 at 1:39 am

    Check the Tested Code Below,

    package stack.examples;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.List;
    
    import android.app.Activity;
    import android.content.ContentResolver;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.provider.ContactsContract;
    import android.provider.ContactsContract.CommonDataKinds.Email;
    import android.view.View;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;
    
    public class RetrieveData extends Activity {
    
        ListView lvItem;
        private Button btnAdd;
        String displayName="", emailAddress="", phoneNumber="";
        ArrayList<String> contactlist=new ArrayList<String>();
        ArrayAdapter<String> itemAdapter;
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
           lvItem = (ListView)this.findViewById(R.id.listView);  
           btnAdd = (Button)this.findViewById(R.id.btn);
           itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,contactlist);
           lvItem.setAdapter(itemAdapter);
           btnAdd.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) {
                   GetEmails();
    
               }
           }); 
        }
    
        private void GetEmails()
            {
    
    
            ContentResolver cr =getContentResolver();
            Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
            while (cursor.moveToNext()) 
            {       
                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));
                    contactlist.add(emailAddress);
    
                }
                emails.close();
                sortList(contactlist);
                itemAdapter.notifyDataSetChanged();
    
            }
            cursor.close(); 
        }  
        private static void sortList(List<String> aItems){
            Collections.sort(aItems, String.CASE_INSENSITIVE_ORDER);
          }
    }
    
    • 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 have seen several questions regarding SocketException when using Android, but none of them
I am currently working on an e-book for the android platform. I'm using Eclipse,
How to include jar files of the Android platform when using the javah tool
i'm using aspectJ in my Android project because of monkeytalk ( cross platform testing
I am using the MvvmCross framework to build a cross platform (iOS, Android, WP7)
I am using phonegap and sqlite to develop cross-platform mobile app for android,ios,blackberry.For reference
We are trying to have an online handwritten text recognizer for the Android platform.
I have learned that when using android:entries with a ListView , it uses android.R.layout.simple_list_item_1
I know this has been covered elsewhere, but I'm new to the Android platform

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.