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