Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is use of Cursor in Android Development?

Tags:

android

cursor

I was going through some of the codes on the internet regarding the database connection, retrieval. I saw Cursor cur1= moveToFirst() in many codes, I wanted to know what is the use of a cursor and why we use moveToFirst() as I am new to android.

like image 596
Rithesh M Avatar asked Mar 30 '12 07:03

Rithesh M


People also ask

What is use of cursor in Android?

A Cursor represents the result of a query and basically points to one row of the query result. This way Android can buffer the query results efficiently; as it does not have to load all data into memory. To get the number of elements of the resulting query use the getCount() method.

What is the use of cursor function?

The major function of a cursor is to retrieve data, one row at a time, from a result set, unlike the SQL commands which operate on all the rows in the result set at one time. Cursors are used when the user needs to update records in a singleton fashion or in a row by row manner, in a database table.

What is use of cursor in SQLite?

Returns the numbers of rows in the cursor. Get the database that this cursor is associated with. This function is called every time the cursor is successfully scrolled to a new position, giving the subclass a chance to update any state it may have.

What is the cursor concept?

1) A cursor is the position indicator on a computer display screen where a user can enter text. In an operating system with a graphical user interface (GUI), the cursor is also a visible and moving pointer that the user controls with a mouse, touch pad, or similar input device.


1 Answers

Cursor is the Interface which represents a 2 dimensional table of any database. When you try to retrieve some data using SELECT statement, then the database will first create a CURSOR object and return its reference to you.

The pointer of this returned reference is pointing to the 0th location which is otherwise called as before first location of the Cursor, so when you want to retrive data from the cursor, you have to first move to the first record so we have to use moveToFirst

When you invokes moveToFirst() method on the Cursor, it takes the cursor pointer to the first location. Now you can access the data present in the first record

like image 161
Chandra Sekhar Avatar answered Oct 20 '22 19:10

Chandra Sekhar