Add fragment containing listview to viewpager

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.