Android Control (a) drop-down refresh: swiperefreshlayout

Source: Internet
Author: User

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

Layout files such as the following.

<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 such as the following:

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. <android.support.v4.widget.SwipeRefreshLayout> can only have a direct sub-class////Main method//Setonrefreshlistener (        Onrefreshlistener): Add a listener//setrefreshing (Boolean) to the layout: Show or hide the refresh progress bar//isrefreshing (): Check whether it is in a refreshed state// Setcolorschemeresource (): Sets the color theme for the progress bar. Up to four public class MyActivity extends Activity implements swiperefreshlayout.onrefreshlistener{private SWIPEREFRESHL    Ayout 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 played in a loop. Just to not finish the refresh will always be circulating, 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 actioN Bar 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.