8

I am using this example to use a ViewPager and a PagerAdapter. But how could I feed the PagerAdapter with data from a adapter like CursorAdapter where I load the data using a CursorLoader?

The .setAdapter() on the ViewPager only takes a PagerAdapter. Then I would guess I need to bind the CursorAdapter within the PagerAdapter, but I could not find a way doing this.

Ron
  • 24,175
  • 8
  • 56
  • 97
OKA
  • 1,453
  • 2
  • 11
  • 7

2 Answers2

4

Here's a blog post where I offer the source code for a CursorPagerAdapter which does what you appear to want.

mlc
  • 1,668
  • 2
  • 16
  • 30
1

You don't need the CursorAdapter, just use the Cursor to populate the views in the PagerAdapter.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • Thanks, but how can I use the `Cursor` from the `CursorLoader` to populate the view (within `instantiateItem`)? – OKA Aug 21 '11 at 19:57
  • 1
    Well there is two ways to go about it: 1. Try to duplicate what `CursorAdapter` does and get data when needed. That basically translates to calling `cursor.moveToPosition(pos)` when you need to get the `View` for position `pos` in your adapter. 2. Don't use a raw `Cursor` but a list of your data (might be easier to implement, especially if don't have too many items). Load all of your data in a list, pass it to the `PageAdapter` and use it populate views as needed. – Nikolay Elenkov Aug 22 '11 at 01:32