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?

Ramon
  • 245
  • 2
  • 4
  • 15

1 Answers1

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

Community
  • 1
  • 1
Suau
  • 4,628
  • 22
  • 28
  • 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 '13 at 08: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 '13 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 '13 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 '13 at 07: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 '13 at 09:29
  • i think this one is pretty good, but very long also http://www.vogella.com/articles/AndroidSQLite/article.html – Suau Jun 20 '13 at 19:04