ListView implements the upload, pull, pull, refresh, and load function. listview pulls down

Source: Internet
Author: User

ListView implements the upload, pull, pull, refresh, and load function. listview pulls down

Step 1: Create a package in your project to store classes that support pull-down refresh and pull-up loading:


Step 2: import two animations to achieve 180-degree rotation and 360-degree rotation:

 

Step 3: import the supported drop-down and hidden load la s of the pull-up display.

 

Step 4: add the content of the strings. xml and colors. xml files to the project:

Strings. xml

<String name = "pull_to_refresh"> pull-down refresh </string>

<String name = "release_to_refresh"> immediate release refresh </string>

<String name = "refreshing"> refreshing... </string>

<String name = "refresh_succeed"> refresh successful </string>

<String name = "refresh_fail"> refresh failed </string>

<String name = "pullup_to_load"> pull up to load more </string>

<String name = "release_to_load"> release and load now </string>

<String name = "loading"> loading... </string>

<String name = "load_succeed"> load successful </string>

<String name = "load_fail"> loading failed </string>
Colors. xml

<Color name = "gray"> # aaaaaa </color>

<Color name = "light_blue"> # 6593cb </color>

Step 5: add the corresponding image to be loaded:

 

Step 6: use custom ListView encapsulated by a third party on the Interface

 

Step 7: Use in activity

In the oncreate method of the form, add a listener event to the current PullToRefreshLayout layout space for listening to pull up and pull down.


Create a listener event, MyListener, and rewrite it in two ways: Pull up and pull down (onLoadMore and onRefresh ). The data source added by pulling up and pulling down must be a temporary set. If the data source is not updated in the UI thread, an error is reported, so the data source is updated in hanlder. The Code is as follows:

Two methods must be added to the corresponding adapter to add data from the beginning and end of the data source set:

 

 

Package yourself in the file

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.