使用选择进行过滤时清空游标行

时间:2015-07-29 10:42:14

标签: android where-clause android-cursor

我对游标没有信心,并且在使用WHERE子句过滤时遇到了一些问题。

我在做什么:

ContentResolver contentResolver = context.getContentResolver();
    Uri uriConversation = Uri.parse("content://mms-sms/conversations/");

    String[] projection = new String[]{"*"};
    String selection = "address=" + phoneNumberForThread;

    Cursor cursor = contentResolver.query(uriConversation, projection, null, null, null);

执行此代码,光标将被填充并完美运行。 但是,如果我将空选择参数与我的选择字符串交换为

Cursor cursor = contentResolver.query(uriConversation, projection, selection, null, null);

然后我得到一个空光标。我甚至检查!phoneNumberForThread.isEmpty()

我认为我做错了什么但是我对光标还没有信心。 任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:2)

如果您的输入变量存储为string数据类型,则应将其'括起来:

String selection = "address='" + phoneNumberForThread + "'";