Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to feed data to PagerAdapter

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.

like image 423
OKA Avatar asked Aug 21 '11 14:08

OKA


People also ask

What is the difference between PagerAdapter and Fragmentpageradapter?

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 .

How to use ViewPager?

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 .

How ViewPager works?

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.


1 Answers

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

like image 182
mlc Avatar answered Sep 27 '22 03:09

mlc