cursor - Load contacts in android in sorting order -


i want load contacts mobile app. piece of code works flawless except not return sorted list. e-d abid 012345678 on top of list abid 012345678 @ end. have tried different combination of cursor (as can see in // comments). looking guidance..

list<contactinfo> loadcontactlistfromphone() {      cursor cursor = getcontentresolver().query(contactscontract.contacts.content_uri, null, null, null, "upper(" + contactscontract.contacts.display_name + ") asc");     //cursor cursor = getcontentresolver().query(contactscontract.contacts.content_uri, null, contactscontract.contacts.has_phone_number + " = 1",  null, "upper(" + contactscontract.contacts.display_name + ") asc");     //cursor cursor = getcontentresolver().query(contactscontract.contacts.content_uri,null, null, null, null);      if(cursor.movetofirst())     {         while (cursor.movetonext())          {              string contactid = cursor.getstring(cursor.getcolumnindex(contactscontract.contacts._id));              string hasphone =  cursor.getstring(cursor.getcolumnindex(contactscontract.contacts.has_phone_number));             int hasph = integer.parseint(hasphone);              if (hasph>-1)             {                  cursor phones = getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null,   contactscontract.commondatakinds.phone.contact_id +" = "+ contactid, null, null);                  if(phones.getcount() > 0)                 {                     while (phones.movetonext())                     {                          string phonenumber = phones.getstring(phones.getcolumnindex( contactscontract.commondatakinds.phone.number));                          string phonename = phones.getstring(phones.getcolumnindex( contactscontract.commondatakinds.phone.display_name));                         list.add(new contactinfo(phonename, 0, phonenumber,0));                     }                 }                 phones.close();              }         }         mylist = list;     }     else     {         toast.maketext(this, "no contact found",toast.length_long).show();     }     cursor.close();      return mylist; } 

try below code

cursor cursor = getcontentresolver().query(contactscontract.contacts.content_uri, null, null, null, contactscontract.commondatakinds.phone.display_name + " collate nocase asc"); 

it working fine me


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -