In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to achieve drop-down refresh and slide to the bottom to load more ListView, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
This article mainly introduces the use of ListView that can simultaneously pull down and refresh and slide to the bottom to load more.
The advantages of the ListView include: a. Customizable drop-down response events (such as drop-down refresh) b. Can be customized to scroll to the bottom to respond to events (such as sliding to the bottom to load more) c. Customizable rich styles d. Efficient (if the drop-down style is turned off, its layout will not be loaded, which is consistent with the efficiency of listView) e. Rich settings.
In this paper, the APK address can be seen as TrineaAndroidDemo.apk, and the runnable code address can be seen as DropDownListViewDemo@Google Code. The results are as follows:
1. Introduce a common library
Introduce TrineaAndroidCommon@GoogleCode as the library of your project, or extract the DropDownListView part of it yourself
2. Define in layout
Replace the ListView tags in the layout with cn.trinea.android.common.view.DropDownListView tags
Add the namespace xmlns:listViewAttr= "http://schemas.android.com/apk/res/cn.trinea.android.demo" of the custom attribute, where cn.trinea.android.demo needs to be replaced with its own package name. How to customize attributes and their namespaces can be found in this article. The xml code is as follows:
DropDownListView customizes three boolean properties
IsDropDownStyle indicates whether drop-down styles are allowed. Drop-down listener can be customized in java code to indicate the tasks that need to be completed.
IsOnBottomStyle indicates whether the bottom style is allowed. The listener scrolling to the bottom can be customized in the java code to indicate the tasks that need to be completed.
IsAutoLoadOnBottom indicates whether to automatically execute the corresponding listener when scrolling to the bottom, which is valid only if isOnBottomStyle is true
PS: if isDropDownStyle or isOnBottomStyle is false, the corresponding layout is not loaded, so the performance is the same as ListView
3. Call in the Java class
Set the drop-down event through setOnDropDownListener, but you need to manually call onDropDownComplete to restore the state at the end of the event
Set the event that scrolls to the bottom through setOnBottomListener, but you need to manually call onBottomComplete to restore the state at the end of the event. The sample code is as follows:
/ * * DropDownListViewDemo * * @ author Trinea 2013-6-1 * / public class DropDownListViewDemo extends BaseActivity {private LinkedList listItems = null; private DropDownListView listView = null; private ArrayAdapter adapter Private String mStrings = {"Aaaaaa", "Bbbbbb", "Cccccc", "Dddddd", "Eeeeee", "Ffffff", "Gggggg", "Hhhhhh", "Iiiiii", "Jjjjjj", "Kkkkkk", "Llllll", "Mmmmmm", "Nnnnnn",} @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState, R.layout.drop_down_listview_demo); listView = (DropDownListView) findViewById (R.id.list_view); / / set drop down listener listView.setOnDropDownListener (new OnDropDownListener () {@ Override public void onDropDown () {new GetDataTask (true). Execute () }}); / / set on bottom listener listView.setOnBottomListener (new OnClickListener () {@ Override public void onClick (View v) {new GetDataTask (false). Execute ();}}); listItems = new LinkedList (); listItems.addAll (Arrays.asList (mStrings)) Adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, listItems); listView.setAdapter (adapter);} private class GetDataTask extends AsyncTask {private boolean isDropDown; public GetDataTask (boolean isDropDown) {this.isDropDown = isDropDown;} @ Override protected String [] doInBackground (Void...) Params) {try {Thread.sleep (1000);} catch (InterruptedException e) {;} return mStrings;} @ Override protected void onPostExecute (String [] result) {if (isDropDown) {listItems.addFirst ("Added after drop down") Adapter.notifyDataSetChanged (); / / should call onDropDownComplete function of DropDownListView at end of drop down complete. SimpleDateFormat dateFormat = new SimpleDateFormat ("MM-dd HH:mm:ss"); listView.onDropDownComplete (getString (R.string.update_at) + dateFormat.format (new Date ();} else {listItems.add ("Added after on bottom"); adapter.notifyDataSetChanged () / / should call onBottomComplete function of DropDownListView at end of on bottom complete. ListView.onBottomComplete ();} super.onPostExecute (result);}
4. Advanced API settings
5. Style settings (custom header and footer information)
The above is all the contents of the article "how to pull down and refresh and slide to the bottom to load more ListView". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.