I have tried the following query but it does not give any result.
SELECT * FROM details WHERE name LIKE :name
I have used AutoCompleteTextview for searching purpose. is there any query to find with a substring?
Like MoinKhan suggested, adding the wildcard to the string before sending to Room worked for me.
query = "%"+query+"%";
I recently ran into this issue and found the nicest solution is to use Sql string concatenation ||
in combination with %
which represents zero, one, or multiple numbers or characters.
@Query("SELECT * FROM details WHERE name LIKE '%' || :name || '%'")
fun getDetails(name: String): details
This will get the details where the name contains the one we are looking for
Similarly the below will find matches that start with the name
LIKE :name || '%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With