Tuesday, April 10, 2012

Android sqlite get boolean from database


was just wondering, how can I obtain the value of a boolean field in a sqlite database in android?



I usually use getString() getInt() etc to get the values of my fields, but there does not seem to be a getBoolean() method.



Any takers?



Kev


Source: Tips4all

4 comments:

  1. If memory serves me right:


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

    ReplyDelete
  2. There is no bool data type in SQLITE. Use an int that you fix to 0 or 1 to achieve that effect. See the datatypes reference on SQLite3.

    ReplyDelete
  3. You can also use
    boolean value =cursor.getString(boolean_column_index).contains("true");

    ReplyDelete
  4. boolean value = (cursor.getInt(boolean_column_index) == 1);

    ReplyDelete