1, Xlistview because added header, will result in the storage of data +1, so the assignment needs position-1. Add: When removing headerview, position does not need-1. 2, make a suggestion: pull load more, preferably in OnCreate () in the execution of Setadapter, and then whether it is empty data, or data, only with the update adapter on the line. One, Xlistview 2, usage
Import a Me.maxwin.view package in a diagram
Two interfaces are available:
Ixlistviewlistener: Trigger drop-down refresh, pull up load more. When this interface is implemented, Onloadmore () is used to pull up the load more, Onrefresh () is used to pull the refresh.
Onxscrolllistener: Same as native onscrolllistener, but fires when header/footer rollback.
Several common methods:
Setpullrefreshenable (Boolean enable): Whether to allow drop-down refreshes
Setpullloadenable (Boolean enable): Whether to allow pull-up to load more
Stoprefresh (): Stop refresh, reset header view
Stoploadmore (): Stop loading more, reset footer view
Stop refresh after request to data stops loading more.
Setrefreshtime (String time): Set when the last refresh
Onloadmore (): The method that is called when loading more. Note This method is not called when you first enter.
Onrefresh (): The method that is called when the drop-down is refreshed.
3, how to express the code
1) Implement Ixlistviewlistener interface->2) to achieve pull-up refresh and pull-down load more data changes->3) Update Header view and footer view and set the update time.
[Java]View Plaincopy
- 1. Implement Ixlistviewlistener interface
- Mlistview.setxlistviewlistener (this);
- Data loading for pull-down refreshes in 2.1 onrefresh
- @Override
- Public void Onrefresh () {
- Request data
Update interface Display
[Java]View Plaincopy
- OnLoad ();
}//2.2 onloadmore load more data in pull-up loading
[Java]View Plaincopy
- @Override
- Public void Onloadmore () {
- Request data
Update interface Display
[Java]View Plaincopy
- OnLoad ();
}//3, after loading the data, reset the header view and footer view, and set the time for the update.
[Java]View Plaincopy
- Private void OnLoad () {
- Mlistview.stoprefresh (); Mlistview.stoploadmore ();
- Mlistview.setrefreshtime ("just");
- }
4. XML Considerations
When the Xlistview is embedded in the LinearLayout, the Xlistview can no longer load more when it fills the full screen. On the error code:
[Java]View Plaincopy
- <linearlayout
- Android:layout_width="Match_parent"
- android:layout_height="Wrap_content"
- Android:layout_above="@id/takemain_ll"
- android:layout_below="@id/takemain_l"
- android:orientation="vertical" >
- <cn.bestbang.durable_consumer_goods.utils.myexxlistview
- android:id="@+id/home_list"
- Android:layout_width="Match_parent"
- android:layout_height="Match_parent" >
- </cn.bestbang.durable_consumer_goods.utils.MyExXListView>
- </LinearLayout>
5, to ScrollView common
In this case, overriding Xlistview will cause frequent errors on the pull-up load: The adapter is not updated and does not know how to resolve it.
Second, Pulltorefresh
Most of the content goes from Yang's blog: http://blog.csdn.net/lmj623565791/article/details/38238749
1, the overall understanding:
First, this control on GitHub: Pull-to-refresh, which is very powerful in the example, can support not only the ListView and the GridView. Before downloading, let's say the project structure. GitHub Downloads The example that is dependent on three items, a basic Library_pulltorefresh (the project itself to be quoted. How to quote? Own project Right-->properties->android, select the path in the is library, a basic Pulltorefreshviewpager, a pulltorefreshlistfragment.
2. Usage
1) Set the Pulltorefreshlistview to support pull-up loading and drop-down refresh->2) initialize the control, set the adapter->3) to set the listener event. Handles pull-up loading more and drop-down refreshes in the listener event, setting the time for the last update.
[Java]View Plaincopy
- <pre name="code" class="java" ><pre name="code" class="java" >//1, Supports pull-up and drop-down refreshes
Mpullrefreshlistview.setmode (Mode.both);
2. Set adapter Madapter = new Arrayadapter<string> (this, Android. R.layout.simple_list_item_1, Mlistitems); Mpullrefreshlistview.setadapter (Madapter); 3. Set Listener Mpullrefreshlistview.setonrefreshlistener (new onrefreshlistener2<listview> () {@Override public void Onpulldowntorefresh (pulltorefreshbase<listview> Refreshview) {//Displays the last updated time Refreshview.getloadinglayoutproxy (). Setlastupdatedlabel (label); Here write down the refreshed task New Getdatatask (). Execute (); } @Override public void Onpulluptorefresh (pulltorefreshbase<listview> refreshview) {//Displays the last updated time Refreshview.getloadinglayoutproxy (). Setlastupdatedlabel (label);
[Java]View Plaincopy
- Here to write up pull load More tasks
New Getdatatask (). Execute (); } });
3. Attribute Introduction
1) ptr:ptrmode= "Both" supports pull-up loading and drop-down refreshes. Disabled disables drop-down refreshes and pull-up loading. Pullfromend only supports pull-up loading. Manualonly only allow manual triggering. Of course through the code can also be set: Lv.setmode (Mode.both);
2) ptr:tranimationstyle= "Flip" flip: Flip animation; rotate: Rotate animation.
3) ptr:ptrdrawable= "@drawable/ic_launcher" setting icon
4) whether the ListView or GridView is allowed to scroll when the ptrscrollingwhilerefreshingenabled is refreshed. Think it's better to be true. 5) ptrlistviewextrasenabled determines the way Header,footer joins Mpullrefreshlistview,true for Headview, which is scrolling when the head refreshes.
4, custom drop-down indicator text content and other effects:
After initialization completes the Pulltorefreshlistview, a Iloadinglayout object can be obtained by Lv.getloadinglayoutproxy (), which sets the styles, text, etc. in various indicators.
[Java]View Plaincopy
- Iloadinglayout startlabels = Mpullrefreshlistview
- . Getloadinglayoutproxy ();
- Startlabels.setpulllabel ("You can pull, pull ..."); The prompt that appears when you just drop down
- Startlabels.setrefreshinglabel ("OK, is refreshing ..."); When refreshed
- Startlabels.setreleaselabel ("You dare to put, I dare to refresh ..."); When it reaches a certain distance, the displayed hints
The default is that the pull-up and drop-down words change at the same time, if you want to change them individually:
[Java]View Plaincopy
- Private void Initindicator () {
- Iloadinglayout startlabels = Mpullrefreshlistview
- . Getloadinglayoutproxy (True, false);
- Startlabels.setpulllabel ("You can pull, pull ..."); The prompt that appears when you just drop down
- Startlabels.setrefreshinglabel ("OK, is refreshing ..."); When refreshed
- Startlabels.setreleaselabel ("You dare to put, I dare to refresh ..."); When it reaches a certain distance, the displayed hints
- Iloadinglayout endlabels = Mpullrefreshlistview.getloadinglayoutproxy (
- false, true);
- Endlabels.setpulllabel ("You can pull, pull 2 ..."); The prompt that appears when you just drop down
- Endlabels.setrefreshinglabel ("OK, refreshing 2 ..."); When refreshed
- Endlabels.setreleaselabel ("You dare to put, I will dare to refresh 2 ..."); When it reaches a certain distance, the displayed hints
- }
Copyright Notice:
ListView drop-down refresh + pull-up load (demo already available)