Looking for help...

Discussion in 'Android Hacks and Help' started by Capt_X, Apr 25, 2010.

  1. Capt_X
    Offline

    Capt_X New Member

    Joined:
    Jan 25, 2010
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Northern VA
    Ratings:
    +0
    I'm running a query against ContactsContract.Data and am trying to concatenate two fields. Below is an excerpt of the code I am working with:

    line numbers inserted for reference

    1- private void populateContactList() {
    2- // Build adapter with contact entries
    3- Cursor cursor = getContacts();
    4- String[] fields = new String[] {
    5- ContactsContract.Data.DATA3 + "," +
    6- ContactsContract.Data.DATA2
    7- };
    8- SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
    9- R.layout.contact_entry, cursor,
    10- fields, new int[] {R.id.contactEntryText});
    11- mContactList.setAdapter(adapter);
    12- }

    My problem is that lines 5 & 6 result in a FC. If I just leave ContactsContract.Data.DATA3 and remove the concatenation with ContactsContract.Data.DATA2 then it works fine.

    I'm not a developer by trade and am really trying to learn. I really appreciate any help anyone can provide.

    Thanks!
     
  2. dot
    Offline

    dot New Member

    Joined:
    Apr 29, 2010
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    I'm probably a bigger nOOb than you are, but in looking at your code I assume you're trying to get a last, first concatenation of a contact. I'm no Java expert but I do notice the pull of DATA3 and then of DATA2. Does your cursor work in both directions or is it forward only?

    Try dropping DATA2 and DATA3 into String variables firstName and lastName and then concatenate the string variables.

    Bill M
     
  3. Capt_X
    Offline

    Capt_X New Member

    Joined:
    Jan 25, 2010
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Northern VA
    Ratings:
    +0
    dot, thanks for your reply. I am trying to do a last, first concatenation of a contact. I've tried declaring string variables lname and fname, but I have a simplecursoradapter that looks for a string array. I haven't figured out how to bring my concatenated string variables into the simple cursor adapter to display the contact name the way I would like.

    I'll try again and see if I can find a way to make it work.

    Thanks again for your response. Appreciate the help!