This question has been deleted and is no more available to answer.
2
I am new to android development and just came from java. There i was using simple Array. Can anyone tell what is use of Cursor in Android Development?

Share using link:

Direct share:

Aug 6 at 5:25:51
Alex
Alex
244

Your answer is here https://developer.android.com/reference/android/database/CursorYellow Daddy Aug 6 at 5:51:37

2 Answers

2
Actually its name makes the new android developers confuse. A cursor is just a simple cursor as we have for the mouse in operating system. But the working behavior of the mouse cursor and the Cursor you are asking about is different.

In case of mouse cursor, when we take this cursor above any object on our screen it means we are accessing this object. For example i move my mouse cursor over Recycle Bin icon, or My Documents icon, it means i am accessing the Bin icon, or My Documents on the screen.

Now lets come to the actual topic. A cursor in android is a type of Data Structure that works from top to bottom. Cursor in android are mostly returned from SQLite database (or can be returned from any other database other than SQLite) in which you can fetch the data from each single row from top to bottom. When the cursor is on the first row you will have the data of first row, once done, the cursor will move to second row, you will have the data of second row, when the cursor will be on the third row, you will and the data of third row and so on. Once you reach the last row, the cursor will say there are no next rows, so you can stop your looping of data retrieval at that point.

So, Cursors are what contain the result set of a query made against a database in Android. Unlike mouse cursor, these works from top to bottom in the retrieved data, vertically.

Now why we use cursors in android?

Cursors are used for efficient data retrieval from the database, which can help to retrieve data within the loop very efficiently. When we have any result set from the database, it is thrown to Cursor data structure and that Cursor object is returned using which we can display the retrieved data, we can stop the loop once we retrieve the last row of the result set.

These are some method you should consider while understanding Cursor:

moveToFirst()
moveToLast()
moveToNext()
moveToPrevious()
moveToPosition(position)

For more visit this link and this link.

Note: The example of mouse cursor is used for the sake of understanding.
Aug 6 at 5:51:3
Jude
Jude
476

thanks million times, this is the best explanation i have ever seen regarding Cursor.Alex Reado Aug 6 at 5:46:52

i am glad it helpsJude Ak Aug 6 at 5:47:50

2
Jude answered very clearly. Cursors are used to retrieve the data rows cursor wise, In each loop iteration the cursor is moved to next row starting from the beginning and go through the end row of the result set. The cursor that is currently pointing the specific row returns its data when we call the column names. Cursor is mostly used for the retrieval of data set from the query.
Aug 6 at 5:45:23
Yellow
Yellow
391

thanks it clear now.Alex Reado Aug 6 at 5:47:13

you welcome @judeYellow Daddy Aug 6 at 5:48:21

Asked
14 days ago
Viewed
31 times