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.
The difference is that you can use Fragments inside a FragmentPageAdapter . If you want to have fragments that are going to be used in other parts of your code this is your Adapter. Otherwise if you only want to have code that isn't going to be reused, you can use PagerAdapter .
You can create swipe views using AndroidX's ViewPager widget. To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .
ViewPager in Android is a class that allows the user to flip left and right through pages of data. This class provides the functionality to flip pages in app. It is a widget found in the support library. To use it you'll have to put the element inside your XML layout file that'll contain multiple child views.
Here's a blog post where I offer the source code for a CursorPagerAdapter
which does what you appear to want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With