How to order Contacts by name?

Asked

Viewed 89 times

0

I have the following code and would like to make an ORDER BY name:

try {
        String clsSimPhonename = null;
        String clsSimphoneNo = null;

        Uri simUri = Uri.parse("content://icc/adn");
        Cursor cursorSim = getContentResolver().query(simUri, null,
                null, null, "name ASC");
        while (cursorSim.moveToNext()) {
            clsSimPhonename = cursorSim.getString(cursorSim
                    .getColumnIndex("name"));
            clsSimphoneNo = cursorSim.getString(cursorSim
                    .getColumnIndex("number"));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

2 answers

0


Having to make a method for ordination:

public List<Telefone> ordenarTelefones(List<Telefone> lista)
        throws Exception {

    Collections.sort(lista, new Comparator<Telefone>() {

        @Override
        public int compare(Telefone tel1, Telefone tel2) {
            return tel1.getNome().compareTo(tel2.getNome());

        }
    });

    return lista;
}

0

Using the last parameter in query, change your Cursor for something like this:

Cursor cursor = getContentResolver.query(simUri, null, null, null, "name ASC");
  • i did Cursor cursorSim = getContentResolver(). query(simUri, null, null, null, Phone.DISPLAY_NAME + "ASC"); and did not change anything.

  • Oops, I missed. Try using "name ASC", this would be the display_name and not the name how you’re using and I haven’t noticed.

  • I had already tested this also did not work.

  • Within that very while You tried printing on the console to see if it’s coming in order at least this stretch? What do you do with these two variables later? The problem may be later yet.

  • while inside did ... Toast.makeText(this, clsSimPhonename, Toast.LENGTH_SHORT). show(); only that and not ordering by contact name.

  • Is it possible to list some items, the ones that are sorted wrong? Are there cases of upper/lower case? We have already done what was necessary, I do not know what can be. (With System.out.println() you can see easier on the console.)

  • I’ll see Dad doing the tests on my phone... I’ll see if I can get in the emulator and print but I think there’s no card^^

  • All contact names start with uppercase letter...

  • I printed it out ....

  • check out this site http://www.frameworksystem.com/blog/mobile-lendo-contactlists-do-android/ I’ve already run the test with the mobile contacts without being from the sim card and order it legal... the problem is only in the ordering of the sim card contacts

  • if you own an android phone try to test to see if in your order.

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.