Retrieving and displaying a contact name from a contact id while using a SimpleCursorAdapter

Posted by Henrique on Stack Overflow See other posts from Stack Overflow or by Henrique
Published on 2011-11-11T17:45:57Z Indexed on 2011/11/11 17:52 UTC
Read the original article Hit count: 251

I am storing information on the phone's contacts using a sqlite database. The fields I am storing are: _id, contact_id, body where _id is the row's id, contact_id is the phone contact's id and body is just a simple text which is the actual information I am storing.

I'm using a SimpleCursorAdapter to map the data to the view, like so:

Cursor cursor = database.fetchInformation(); // fetch info from DB
    String[] from = new String[] { CONTACT_ID, BODY };
    int[] to = new int[] { R.id.contact, R.id.body };

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
    getListView().setAdapter(adapter);

What I would actually want is to get the contact name that is associated with this CONTACT_ID, and have that be shown in the view.

I can't seem to find a simple solution. I've tried implementing my own SimpleCursorAdapter and rewriting setViewText(TextView, String) but it didn't work. Also, it just seems overly complicated for such a simple task.

Any help? Thanks.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-listview