Don't talk about fragment. Read the API manual directly.
Adding fragment containing listview to viewpager is troublesome. What he shows is the sliding paging effect of the news client.
The code will not be pasted here. Let's just take a look. Code has time to re-stick:
1. You need a viewpager: during the experiment, there is only one viewpager in my activity. Nothing else.
2. You need a custom fragment. Here, there is a listview in this fragment (only one listview is available in the layout file)
To fill the listview with data, we need a custom baseadapter in fragment to fill the data in the listview.
3. An object class util is used to represent data in each item of listview.
4. You need a custom fragmentpageradapter. In this example, the adapter adds fragment to viewpager. (Pageradapter adds a view to viewpager. Fragment cannot be added .)
Therefore, we need four classes: Custom fragment, custom fragmentpageradapter, custom baseadapter, and data entity class util.
The filling process is as follows:
1. Prepare a data fragment set in the activity (an util set must be created if no fragment is created. The data of the listview in this fragment), used to fill the viewpager.
2. Create the fragmentpageradapter and fill the fragment in viewpager.
3. When the fragment is created, the util dataset uploaded to the fragment is filled in with the custom baseadapter to its own listview.
4. The filling is complete.
Add fragment containing listview to viewpager