0

after going through loads of tutorials on CursorLoader for using with a SQLiteDatabase, I'm still a bit confused. Being a beginner, I was unaware of the advantages of Listview and instead chose to use several ViewGroups in a vertical order in my first app.

Now that my app is complete and I want to optimize it by using a CursorLoader for doing all the SQL operations (CRUD), I don't have any idea how to implement it.

Is it possible to extract the information from the returned adapter and update the TextViews inside the ViewGroups?

Furthermore, I'm using a DatabaseHelper for all my SQL requirements. Do I need to re-write it to use a Loader? How tough would it be?

Sorry if this is a naive question, but the official documentation are not at all clear.

1 Answer 1

1

Is it possible to extract the information from the returned adapter

There is no "returned adapter". CursorLoader is a Loader that returns a Cursor. None of those things are "adapters" as the term is used in Android.

and update the TextViews inside the ViewGroups?

Yes. The Cursor API allows you to set which row you want to work with (moveToPosition(), etc.), from which you can retrieve columns (getString(), etc.).

Do I need to re-write it to use a Loader?

CursorLoader works only with a ContentProvider. If your DatabaseHelper (presumably a subclass of SQLiteOpenHelper) is used by a ContentProvider, then your CursorLoader can work with that ContentProvider. Other alternatives include:

  • not bothering with the Loader framework, and just using AsyncTask and kin for doing your database I/O in the background

  • using my SQLiteCursorLoader, which works directly with a SQLiteOpenHelper

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, looks like your SQLiteCursorLoader is exactly what I was looking for! Thanks a lot for your quick answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.