Get boolean from database using Android and SQLite

后端 未结 10 1509
情话喂你
情话喂你 2020-12-07 09:02

How can I obtain the value of a boolean field in an SQLite database on Android?

I usually use getString(), getInt(), etc. to get the values

10条回答
  •  轮回少年
    2020-12-07 09:59

    boolean datatype is not available in Cursor.

    you will get the result in an int, so you need to convert that int value to a boolean.

    You can either use

    boolean b = cursor.getInt(boolean_column_index) > 0;
    

    or

    boolean b = (cursor.getInt(boolean_column_index) != 0);
    

提交回复
热议问题