Android Control (a) drop-down refresh: swiperefreshlayout

Source: Internet
Author: User

It is important to note that Swiperefreshlayout can only have one direct child node below.

The layout file is as follows.

<framelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:id=" @+id/container "    android:layout_width=" Match_parent "    Android : layout_height= "match_parent"    tools:ignore= "Mergerootframe" >    < Android.support.v4.widget.SwipeRefreshLayout        android:id= "@+id/swipe_container"        android:layout_width= " Match_parent "        android:layout_height=" match_parent ">        <listview            android:id=" @+id/list            " Android:layout_width= "Match_parent"            android:layout_height= "match_parent" >        </ListView>    </android.support.v4.widget.SwipeRefreshLayout></FrameLayout>

The main program is as follows:

Package Com.francis.swiperefreshlayouttest;import Android.app.activity;import Android.content.intent;import Android.os.bundle;import Android.os.handler;import Android.view.menu;import Android.view.menuitem;import Android.support.v4.widget.swiperefreshlayout;import Android.widget.arrayadapter;import android.widget.ListView;/ /Layout file under,<android.support.v4.widget.swiperefreshlayout> can only have a direct subclass////Main method//Setonrefreshlistener (OnRefreshL Istener): Add a listener//setrefreshing (Boolean) to the layout: Show or hide the refresh progress bar//isrefreshing (): Check whether it is in a refreshed state//Setcolo Rschemeresource (): Sets the color theme for the progress bar to set up to four public class MyActivity extends Activity implements    swiperefreshlayout.onrefreshlistener{private Swiperefreshlayout mswipelayout;    Private ListView Mlistview;    Private arrayadapter<string> Marrayadapter;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_my); String[] StriNGS = new string[] {"A", "B", "C", "D"}; Marrayadapter = new Arrayadapter<string> (this,android.        R.layout.simple_list_item_1,strings);        Mswipelayout = (swiperefreshlayout) Findviewbyid (R.id.swipe_container);        Mswipelayout.setonrefreshlistener (this);                The load color is looped, as long as the refresh does not complete, it will always loop, Color1>color2>color3>color4 mswipelayout.setcolorschemeresources ( Android. R.color.holo_blue_bright, Android. R.color.holo_green_light, Android. R.color.holo_orange_light, Android.        R.color.holo_red_light);        Mlistview = (ListView) Findviewbyid (r.id.list);    Mlistview.setadapter (Marrayadapter); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the Actio        n Bar if it is present.        Getmenuinflater (). Inflate (r.menu.my, menu);    return true; } @Override public boolean onoptionsitemselected (MenuItem Item) {//Handle actionBar item clicks here.  The action bar would//automatically handle clicks on the Home/up button, so long/As you specify a parent        Activity in Androidmanifest.xml.        int id = item.getitemid ();        if (id = = R.id.action_grid_view) {startactivity (new Intent (Myactivity.this,gridviewtest.class));    } return super.onoptionsitemselected (item);            } @Override public void Onrefresh () {new Handler (). postdelayed (New Runnable () {@Override            public void Run () {//Stop flushing mswipelayout.setrefreshing (false);    }}, 3000); }}


Android Control (a) drop-down refresh: swiperefreshlayout

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.