1

I have two SQLite tables:
Service: sid (prim.key), workDesc, title
ServiceInstance: ssid (prim.key), sid(foreign key), date, workComment, odometer

Today I'm using a CustomAdapter extending SimpleCursorAdapter to feed a ListView with data from these tables. But since this method is deprecated, I want refactor the code using LoaderManager/CursorLoader instead.

Now, my confusion is that in the ListView, I want to show the date from the ServiceInstance table and the title from the Service table. Like:
2013-06-05 Regular service

How can I do that? Since now when I'm using my extended SimpleCursorAdapter-class, I'm sending a cursor to the constructor. But in this case when I have changed the database structure a bit, I need to show data from two different cursors (Service and ServiceInstance).

I have googled and read a couple of tutorials but not found any similar case. But here, http://www.mysamplecode.com/2012/11/android-database-content-provider.html

Where they declare the string array columns (step 6, MainActivity.java:58), can I just add the column names (date and title) even though they exist in different tables?

Another question, I don't plan to provide these data to other apps, so is it a meaning to create a ContentProvider anyway?

1 Answer 1

0

it shouldn't be necessary to bind to two different cursors in your case (and i wouldn't recommend it, since you would have to write your own adapter in that case).
Try to query across your tables instead, check this for a starting point:

For your second question, if you don't want to expose your ContentProvider to other applications set:

<provider
    ....
    android:exported="false">
</provider>

in your manifest

6
  • Regarding my second question, I wonder what I should pass to the CursorLoader constructor, since it requires a URI as second argument?
    – Ramon
    Jun 12, 2013 at 8:48
  • The Uri as defined in your content provider, let me know if you need an example (I'm on holidays and will be back at a computer next week).
    – Suau
    Jun 13, 2013 at 13:22
  • I know that, but I don't plan to provide these data to other apps, so is it possible to not use a ContentProvider? Or is it better to create one anyway?
    – Ramon
    Jun 13, 2013 at 13:44
  • i would create one, and just set the android:exported="false", it's convenient to use once setup, you could use a CursorLoader without a content provider, but it requires some workarounds. I wouldn't recommend it.
    – Suau
    Jun 17, 2013 at 7:04
  • Thanks for your advice! Workarounds are not something I'm striving for, so I will create one and not export it. Just need to find a good example, do you have one available?
    – Ramon
    Jun 17, 2013 at 9:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.