Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CursorLoader to query SQLite DB and populate AutoCompleteTextView

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).

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?

like image 430
mraviator Avatar asked Mar 28 '12 17:03

mraviator


People also ask

What is CursorLoader?

A CursorLoader is a specialized member of Android's loader framework specifically designed to handle cursors. In a typical implementation, a CursorLoader uses a ContentProvider to run a query against a database, then returns the cursor produced from the ContentProvider back to an activity or fragment.

Is Cursor Loader deprecated?

This class was deprecated in API level 28.


1 Answers

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

SimpleCursorAdapter has a new constructor:

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

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

like image 144
FatihC Avatar answered Oct 20 '22 19:10

FatihC