如何在 Android 应用程序中获取 SQLite 数据库的 URI?

发布于 2024-10-08 09:56:27 字数 181 浏览 0 评论 0原文

我有一个 Android 应用程序,其中有一个名为“myTestDB”的数据库和一个名为“list_items”的表。我想使用 Cursor getContentResolver().query() 方法来获取要添加到 SimpleCursorAdapter 的游标。 query() 方法的第一个参数是 URI,我不确定 URI 应该是什么样子。

I have an Android app with a database called "myTestDB" with a table called "list_items". I want to use the Cursor getContentResolver().query() method to get a cursor to add to a SimpleCursorAdapter. The first argument of the query() method is a URI and I'm not sure what the URI should look like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独享拥抱 2024-10-15 09:56:27

您不使用 getContentResolver() 直接访问 SQLite 数据库。与内容提供商合作时,您可以使用 getContentResolver()。您对 SQLiteDatabase 对象调用 query() 来获取与 SimpleCursorAdapter 一起使用的 Cursor

You do not use getContentResolver() to access a SQLite database directly. You use getContentResolver() when working with content providers. You call query() on a SQLiteDatabase object to get a Cursor for use with SimpleCursorAdapter.

苹果你个爱泡泡 2024-10-15 09:56:27

数据库没有 Uri(除了它所在的文件之外)。通过内容提供商管理的数据有一个。如果要使用内容解析器来执行查询,则需要先编写内容提供器。

如果您不想这样做,只需使用 SQLiteDatabase 的 query 函数 - 它返回一个 Cursor,您可以将其传递给 SimpleCursorAdapter。

A database doesn't have a Uri (other than the file where it's located). Data managed through a content provider has one. If you want to use the content resolver to perform a query, you need to write a content provider first.

If you don't want to do that, simply use SQLiteDatabase's query function - it returns a Cursor that you can pass to the SimpleCursorAdapter.

偏爱自由 2024-10-15 09:56:27

它相当简单 方法调用看起来像这样

mDataBase.query(TABLE_NAME, columns, null, null, null, null, null);

其中,TABLE_NAME = 你的 SQLite 表名称,columns 是一个字符串数组,例如

String columns[] = new String[] { "Column1" };

如果您想要所有列,则可以为第二个参数传递 null

更正:正如其他一些人提到的,没有 URI。

it is fairly straightforward Method call looks like this

mDataBase.query(TABLE_NAME, columns, null, null, null, null, null);

where, TABLE_NAME = your SQLite table name and columns is a string array like

String columns[] = new String[] { "Column1" };

If you want all columns, you can pass null for second argument.

Correction: As mentioned by a few others, there is no URI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文