游标在Android开发中的用途是什么? [英] What is use of Cursor in Android Development?

查看:90
本文介绍了游标在Android开发中的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览Internet上有关数据库连接,检索的一些代码.我在许多代码中都看到了Cursor cur1= moveToFirst(),我想知道游标的用途以及为什么我们使用moveToFirst(),因为我是Android新手.

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.

推荐答案

游标是表示任何数据库的二维表的接口.当您尝试使用 SELECT 语句检索某些数据时,数据库将首先创建一个 CURSOR 对象,并将其引用返回给您.

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.

此返回引用的指针指向第0个位置,否则称为光标的第一个位置.您要从游标中检索数据,必须首先移至第一条记录,因此我们必须使用 moveToFirst

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

当您在光标上调用 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

这篇关于游标在Android开发中的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆