可以为内容提供商使用IN子句吗?
我目前正在使用
- cursor = contentResolver.query(CONTENT_URI,PROJECTION,"field IN (?)",new String[] { argsBuilder.toString() },null);
我的光标值为0.
帮帮我?
解决方法
使用IN运算符时,需要有一个?用您在selectionArgs数组中提供的每个参数以逗号分隔.例如.:
- String[] selectionArgs = {"red","black"};
- String selection = "color IN (?,?)";
以下选择正确的计数和适当的参数:
- int argcount = 2; // number of IN arguments
- String[] args = new String[]{ 1,2 };
- StringBuilder inList = new StringBuilder(argcount * 2);
- for (int i = 0; i < argcount; i++) {
- if(i > 0) {
- inList.append(",");
- }
- inList.append("?");
- }
- cursor = contentResolver.query(
- CONTENT_URI,"field IN (" + inList.toString() + ")",args,null);