O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading cursor columns

Consider the following lines:

final int id = cursor.getInt(cursor.getColumnIndexOrThrow    (StockUpdateTable.Columns.ID));

These and the rest are responsible for fetching the data from the cursor. First of all, it looks up the index of the column by the name using the following:

cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.ID)

Then, the actual value is retrieved using this:

cursor.getInt(...);

For the readers who are unfamiliar with SQLite, the values in the Cursor object are encoded by index and that index represents a column from where the data was retrieved. However, we can look up the index for the column automatically by calling cursor.getColumnIndexOrThrow(), where the name for the column is supplied ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required