我正在尝试批量删除表格中的一些项目。
String ids = { "1", "2", "3" };
mContentResolver.delete(uri, MyTables._ID + "=?", ids);
但是我不断收到以下错误
java.lang.IllegalArgumentException: Too many bind arguments. 3 arguments were provided but the statement needs 1 arguments.
最佳答案
您可以使用 ContentProviderOperation用于在一个事务中批量删除/插入/更新。您不必连接字符串会更好。它也应该非常有效。删除:
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
ContentProviderOperation operation;
for (Item item : items) {
operation = ContentProviderOperation
.newDelete(ItemsColumns.CONTENT_URI)
.withSelection(ItemsColumns.UID + " = ?", new String[]{item.getUid()})
.build();
operations.add(operation);
}
try {
contentResolver.applyBatch(Contract.AUTHORITY, operations);
} catch (RemoteException e) {
} catch (OperationApplicationException e) {
}
关于android - 在 Android 中使用 Content Provider 批量删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11458707/