(Source code introduction
In the software list of the Android Market, 10 records are displayed on each page, and there are no buttons for the previous page and the next page. Data is dynamically loaded by manual sliding. When scrolling down, loading Displayed at the bottom. After data loading, the loading bottom column disappears. For the segmented display of listview, there are ready-made libraries available, such as CWAC endless. The disadvantage of this library is that the view loaded at the bottom cannot be customized. There is also an androidpageablelistview on Google Code, which can realize basic paging. There are buttons to manually display the previous page and the next page. After consulting a lot of materials, I found that listview actually has its own method for page loading. The two functions addfooterview/removeview are used to "add" or "delete" the listview footer. The following is a demo for learning listview paging. It is relatively simple. I will share my source code with you, hoping to help you.
The implementation idea is as follows: use onscroll method to realize "sliding"; Post processing check whether there are new records. If yes, call addfooterview to add the record to the adapter, and the adapter calls notifydatasetchanged to update the data; If there are no records, remove the customized mfooterview. The onscrollstatechanged function is not overridden here, so an external variable mfirstcell is required to record the sliding position in onscroll.
Note: This is just a simple demo to help understand the process and the use of related methods (mainly the use of onscroll method). The data in the adapter in the demo directly uses the data written in the program, so the downward sliding method may not be obvious in the loading bar I see, so a toast reminder is specially written. For commercial applications, asynctask is usually used to communicate with the server to obtain data, so the effect will be obvious (you can see the major software stores, such as Google Android store, eoemarket, Amy software store, etc.).)