title: Contact list isn't in Alphabetical order in Listview
body: <p>I am using the Android Eclair 2.1 platform.</p>
  
  <p>The working behind this code is, it will access all the contacts from the Emulator and will display in the list view for each contact like this</p>
  
  <p><strong>Contact Name, Contact Number, Email</strong></p>
  
  <p>There are 2 issues for this code is</p>
  
  <ol>
  <li>I did run the program, after that I created a new contact it won't be in alphabetical order</li>
  </ol>
  
  <p>[ eg : when I create a name starting from B it wouldn't go after A, instead it go to the last place ]</p>
  
  <p>2.If a contact has no Email or Number it will receive the previous contact's Email or Number</p>
  
  <p>Here is the 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_PH    ONE_NUMBER))) &gt; 0)
  {
      Cursor pCur =cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDat     aKinds.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();
   }
  cursor.close(); 
   }
   }
  </code></pre>
  
  <p>Any link or site to refer and study to solve this problems if so send me the link ? </p>