[英]How can I fetch data from my Database using Room when the input query is only part of that data?
我在 DAO 中有以下代碼,試圖為我的軟件電話應用程序創建“快速搜索”function:
// Retrieve the numbers matching the query (e.g. for dialer quick search)
@Query("SELECT * FROM phone_numbers_table WHERE phone_number LIKE :phoneNumber")
List<PhoneNumber> getMatchingNumbers(String phoneNumber);
在撥打號碼時,我希望我的應用程序獲取其中包含當前輸入的字符串的所有聯系人號碼(即,如果我輸入了“456”,我想獲取其中包含“456”的所有號碼)。 但是,上面的代碼只返回與輸入查詢完全匹配的數字。
如何更改我的代碼以返回我需要的內容?
應該更徹底地搜索,這是答案:
// Retrieve the numbers matching the query (e.g. for dialer quick search)
@Query("SELECT * FROM phone_numbers_table WHERE phone_number LIKE '%' || :phoneNumber || '%'")
List<PhoneNumber> getMatchingNumbers(String phoneNumber);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.