What is cursor in android?

Asked 06-Apr-2018
Viewed 2754 times

1 Answer


2

Cursor In Android
Cursors is a class that are used to store result set of a query which made against database in android. Cursor class contain powerful API that allows an application to read the columns and returned the query string. When using the cursor then multiple threads are perform its own synchronization. By using cursor we can save lot of ram and memory.

The cursor is defined in the following ways:
Public cursor cursorFunction()
{
Cursor cursor = sqLiteDatabase.query( tableName, tableColumns, whereClause, whereArgs, groupBy, having, orderBy);
Return cursor;
}

For creating cursor, we can pass different arguments like tableName, columnName ,whereCluse, groupBy, Having, orderBy  etc after that we receive the cursor. In order to get the no. of columns and rows data, then we use following code-
Int totalColumn=cursor.getColumnCount();
Int totalRow=cursor.getCount();
 For finding the column name, we use following code.
String[] columnName = cursor.getColumnNames();
The cursor are used to points a single row at a time and any query in SQLite database returns a cursor object.