What is cursor in android?

1 votes
Prateek sharma asked 06-Apr-2018 in Android by Prateek sharma

1 Answer

2 votes
Arti Mishra answered 10-Apr-2018 by Arti Mishra
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.