Search code examples
androidandroid-cursor

Query using where condition in Android


I want to set a query to get names which cointain the a particular string (here constraint). SO I coded:

Cursor contactCursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{Phone.DISPLAY_NAME}, Phone.DISPLAY_NAME + "like + ?", new String[]{"%"+constraint+"%"}, Phone.DISPLAY_NAME + " ASC");

But I get en error. I know that I'm close. Where I'm wrong?


Solution

  • You have a simple typo. Change this:

    "like + ?"
    

    to this:

    " like ?"
    

    (add a space in the front and remove the +).