android - 如何检查Cursor的空值?

标签 android android-cursor isnull

我需要检查列值是否为空。 documentation says :如果指示列中的值为 null,则 isNull 返回 TRUE。 因此,我尝试在代码中实现此功能:

if (c.isNull(c.getColumnIndex("description")))
            description.setText("The column is null");
        else
            description.setText(c.getString(c.getColumnIndex("description")));

但即使该列为空,我也不会在条件中得到 true 。为什么会发生这种情况?

谢谢。

最佳答案

int index = c.getColumnIndex("description");
String str = c.getString(index);
if (str == null || str.isEmpty() || str.equalsIgnoreCase("null")) {
    description.setText("Empty!");
} else {
    description.setText(str);
}

关于android - 如何检查Cursor的空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25836883/

相关文章:

将值类型装箱为 msg.obj 时 android.os.Handler.removeMessages 不起作用

android - 如果不赞成重新查询,现在如何重新查询游标?

android - 启动应用程序时获取新短信的更快/最快的方法 - Android

android - 如何从 sqlite 游标中获取列值?

MySQL LEFT JOIN 和 IS NULL

mysql - 删除 SQL 中的 NULL 值 JOIN 和 SQL 中的 UNION 运算符

android - 在可绘制文件中修改png文件后,它仍然在手机运行中显示旧图标

android - RecyclerView Item装饰间距和跨度

mysql - 如果行中的值不在 SQL 的其他表中,如何使行中的值显示为 NULL

java - firebase addvalueeventlistener 未在一台设备中触发