Android system comes with the implementation of the drop-down refresh control, android Control

Source: Internet
Author: User

Android system comes with the implementation of the drop-down refresh control, android Control

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:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/swipe_refresh"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <ScrollView        android:id="@+id/scrollview"        android:layout_width="match_parent"        android:layout_height="match_parent" >                <LinearLayout             android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="vertical"            >                        <TextView                 android:id="@+id/tip_text"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="@string/pull_fresh"                android:textSize="15sp"                />            <TextView                 android:id="@+id/random_text"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:textColor="#FF000000"                android:textSize="15sp"                />                    </LinearLayout>            </ScrollView></android.support.v4.widget.SwipeRefreshLayout>

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 );}}


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.