Implementation of the pull-down refresh control in the android system

Source: Internet
Author: User

Implementation of the pull-down refresh control in the android system

The drop-down refresh control SwipeRefreshLayout provided by android is located in the android. support. v4.widget package. The implementation steps are as follows:

1. Add the control to the layout file. This control is generally used as the parent control and can only contain one child control, which can be slide, such as scrollview and listview.

2. Implement the OnRefreshListener interface and rewrite the onRefresh function.

 

The Code is as follows:

 

 

Import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. support. v4.widget. swipeRefreshLayout; import android. support. v4.widget. swipeRefreshLayout. onRefreshListener; import android. widget. textView;/*** MainActivity --- implement the system pull-down refresh control * @ author seabear **/public class MainActivity extends Activity implements OnRefreshListener {private SwipeRefreshLayout listener; private TextView mRandomText; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); mSwipeRefreshLayout = (SwipeRefreshLayout) this. findViewById (R. id. swipe_refresh); mSwipeRefreshLayout. setOnRefreshListener (this); mRandomText = (TextView) this. findViewById (R. id. random_text) ;}@ Overridepublic void onRefresh () {mSwipeRefreshLayout. setRefreshing (true); (new Handler ()). postDelayed (new Runnable () {@ Overridepublic void run () {// stop refreshing mSwipeRefreshLayout after 3 seconds. setRefreshing (false); int num = (int) (Math. random () * 100 + 1); String s = mRandomText. getText (). toString (); s = s ++ num; mRandomText. setText (s) ;}}, 3000 );}}


 

 

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.