使用CursorLoader查询的SQLite数据库,并填充AutoCompleteTextView数据库、CursorLoader、SQLite、AutoCompleteTextView

2023-09-06 13:24:50 作者:世俗

我有一个SQLite数据库,我想查询。我想通过ICS为目标的A​​ndr​​oid 2.2。我碰到this本文就如何做到这一点,但它使用德precated code(不会异步查询,但在UI线程上)。我因为读,我可以使用 CursorLoader 以及 LoaderManager 做这个任务的preferred,最好已经实践的方式(以不陷入瘫痪UI线程)。

I have a SQLite database I would like to query. I want to target Android 2.2 through ICS. I came across this article on how to do this, but it uses deprecated code (does not query asynchronously, but on the UI thread). I've since read that I can use CursorLoader along with LoaderManager to do this task the preferred, best practices way (as to not bog down the UI thread).

问题是要找到一个的简洁的例子来向我解释如何做到这一点。 1)加载数据库,2)进行查询,3)用结果来填充AutoCompletetextBox列表视图。

The problem is finding a concise example to explain to me how to do this. 1) Load the database, 2) query it, 3) use the result to populate an AutoCompletetextBox list view.

有没有这样的例子存在?

Does such an example exist?

推荐答案

我知道这是一个老问题,但人谁访问这个页面:

I know this is an old question but for people who visit this page:

SimpleCursorAdapter 有一个新的构造:

SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)

这cunstructor不使用UI线程。你可以用它safey。

this cunstructor does not use UI thread. You can use it safey.