I was going through some of the codes in the internet regarding the database connection, retrieval. I saw Cursor cur1= moveToFirst()
in many codes,i wanted to know what is the use of cursor and why we use moveToFirst()
as i am new to android.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
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
Cursor is like ResultSet in java, it has rows returned by some queries with its pointer.
moveToFirst()
,moveToNext()
andmoveToPosition(position)
sets the pointer to desired postion.Cursor interface provides random read-write access to the result set returned by a database query.
Cursor implementations are not required to be synchronized so code using a Cursor from multiple threads should perform its own synchronization when using the Cursor.
Cursor is an interface which is used as a collection to represent data. It is similar to cursors in PL/SQL, it holds the rows (one or more) returned by some queries with its pointer. moveToFirst(), moveToLast() ,moveToNext(),moveToPrevious() and moveToPosition(position) are methods available in cursor which iterates through the cursor and sets the pointer to desired position.
In simple words, Cursor is a Interface whice returns collection of your query data.
moveToFirst()
is used to point the cursor position from where you want to get data from your cursor. There are methodsmoveToLast()
,moveToNext()
,moveToPrevious()
,moveToPosition(position)
by which you can iterate through your cursor by desired way.For example, you have data in your Cursor
moveToFirst()
- If you usecursor.moveToFirst()
then in this case it will point Lalit, as it is the first data in your cursor. To get the next data from cursor you can usemoveToNext()
.moveToLast()
- This will point Chandra as the current data in your cursor. To get the previous data from cursor you can usemoveToPrevious()
A cursor is what any SQL query result will be stored in.