Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use LIKE clause in query function
    primarykey
    data
    text
    <p>I am making an application which search messages in the inbox based on sender number. Here is my code:</p> <pre><code>public void onClick(View v) { Toast.makeText(this, "search", Toast.LENGTH_LONG).show(); final Uri SMS_INBOX = Uri.parse("content://sms/inbox"); String[] colList = {"address", "body"}; Cursor c = getContentResolver().query(SMS_INBOX, colList, null, null,"DATE desc"); String yz= String.valueOf(c.getCount()); Toast.makeText(this, yz, Toast.LENGTH_LONG).show(); if(c.moveToFirst()) { Toast.makeText(this, searchtxt.getText(), Toast.LENGTH_LONG).show(); for(int i=0;i&lt;c.getCount();i++) { String number=c.getString(c.getColumnIndexOrThrow("address")).toString(); boolean match = number.toUpperCase().indexOf(searchtxt.getText().toString()) != -1; if (match) { Toast.makeText(this, String.valueOf(i), Toast.LENGTH_LONG).show(); String body= c.getString(c.getColumnIndexOrThrow("body")).toString(); tv.setText(tv.getText() + "\n" + body); } c.moveToNext(); } } else { Toast.makeText(this, "Inside else", Toast.LENGTH_LONG).show(); } c.close(); } </code></pre> <p>The above code works fine but it retrieves all the messages in the inbox. I want that it should retrieve only those messages which match the sender number. For that I tried a query using LIKE clause, but with that it returns 0 records. What is the correct way of using the LIKE clause. Here is the code that I tried using LIKE</p> <pre><code>String[] colList = {"address", "body"}; String[] argList = {"'%"+searchtxt.getText().toString()+"%'"}; Cursor c = getContentResolver().query(SMS_INBOX, colList, "address LIKE ?", argList,"DATE desc"); String yz= String.valueOf(c.getCount()); Toast.makeText(this, yz, Toast.LENGTH_LONG).show(); </code></pre> <p>Please help me out....Thank you...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload