我想根據therir ID獲取聯繫人列表的光標。我不確定如何將「IN」語句與一組參數一起使用。我目前造成的錯誤。ContentResolver和「IN」語句中的「where」條件
public Cursor GetContacts(String[] ids)
{
ContentResolver cr = getContentResolver();
try
{
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER
};
String where = ContactsContract.Contacts._ID + " IN ?";
String[] selectionArgs = ids;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME;
return cr.query(uri, projection, where, selectionArgs, sortOrder);
}
catch (Exception ex)
{
String message = ex.getMessage();
Log.e("mine", "Error: " + message, ex);
return null;
}
錯誤:近 「?」:語法錯誤(代碼1):在編譯:選擇_id,DISPLAY_NAME,has_phone_number FROM view_contacts WHERE((1))AND((_id IN)?)ORDER BY DISPLAY_NAME
它會導致哪個錯誤? – duplode
@duplode,我更新了我的問題 – Anarion
您是否試圖根據一個id或幾個基於ID數組的結果返回一個結果? –