想象一下以下电话簿:
A
123456
B 与 Android
654321
C
112233
使用 Android 进行 D
778899
我想检索包含“with Android”的联系人。我们的想法是使用“使用 Android”作为选择标准。
我尝试过以下方法:
String[] projection = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
String where = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " LIKE ?";
String selection = " with Android";
String[] selectionArgs = {selection};
Cursor myCursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection, where, selectionArgs, null);
我也尝试过使用 "=?" 代替 "LIKE ?" 但没有得到结果。
提前致谢!
最佳答案
我也是android新手,但我认为这可能对你有帮助
实际上,您尝试获取匹配字符串的查询字符串是错误的。 当使用like...时,如果你想获取与某个文本匹配的某些字符串,你需要将查询字符串指定为:-
SELECT * FROM customers
WHERE 'Robert Bob Smith III, PhD.' LIKE '%mit%';
在 android 中,选择参数作为字符串数组传递
像这样更改您的代码:
String where = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " LIKE ";
String selection = "%with Android";
String[] selectionArgs = {selection};
请检查一下
关于java - 如何在android中检索包含特定单词的联系人姓名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18961199/