Android logs: Google official drop-down refresh control

Source: Internet
Author: User

Recent projects compared to rush, so there is little time to write a blog, feel that their new knowledge is too little. Occasionally visit the post, see Google new pull up the space to refresh, feel very interesting, I tried to do a demo, the effect is really good. Let's share it.

First, it must be explained that this control only needs to download the newer API, at least 19, because it is an additional jar package, so backwards compatible with each Android version. The previous effect was a line at the top, and after updating the SDK it now turns into a circle, with the same usage.

Main file:

Public class mainactivity extends actionbaractivity {private swiperefreshlayout  refreshLayout; private GridView gv;private MyAdapter adapter;private  arraylist<string> mdatas;//private listview lv; @Overrideprotected  void oncreate (bundle savedinstancestate)  {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_ Main); Initview ();} /** *  initializing Data  */private void initdata ()  {mDatas = new ArrayList< String> ();for  (int i = 0; i < 10; i++)  {mDatas.add ("No."  + i +  "bar Data");}} Private void initview ()  {refreshLayout =  (swiperefreshlayout)  findviewbyid ( R.id.swiperefresh); gv =  (GridView)  findviewbyid (R.ID.GV);//lv =  (ListView)  findviewbyid (r.id.lv);  gv.setnumcolumns (3); Mdatas = new arraylisT<> (); InitData (); Adapter = new myadapter ();  gv.setadapter (adapter);//lv.setadapter ( Adapter);//  Set the color of the loaded animation/** *  (int colorres1  slide when the telescopic color, int  the second color,  int   Third color, int  fourth color)  *  This processing order is the order in which the color of the jump display is refreshed on the interface  */ Refreshlayout.setcolorschemeresources (Android. R.color.holo_blue_bright,android. R.color.holo_red_light,android. R.color.holo_green_light,android. R.color.holo_orange_light); Refreshlayout.setonrefreshlistener (New onrefreshlistener ()  {@ Overridepublic void onrefresh ()  {//  here handles the refreshed event, looking at its own project, generally using asynchronous loading data, New myasynctask (). Execute ("");}}); /** *  asynchronously loading data  *  *  @author  think *  */private class  myasynctask extends asynctask<string, string, boolean> {@ Overrideprotected void onpreexecute ()  {super.onpreexecute ();} @Overrideprotected  boolean doinbackground (string... pArams)  {//  Asynchronous Load Data//  example: LV adds a data mdatas.add ("New data");//  in order to simulate the real situation we will sleep  2 seconds Time Systemclock.sleep (+); return true;} @Overrideprotected  void onpostexecute (Boolean result)  {super.onpostexecute (result);   (Result)  {adapter.notifydatasetchanged ();//  stop swiperefreshlayout Refresh refreshlayout.setrefreshing ( false);}}} /** *  Fill Data  *  *  @author  think *  */private class  myadapter extends baseadapter {private textview mtv; @Overridepublic  int  GetCount ()  {return mdatas.size ();} @Overridepublic  object getitem (int position)  {return mdatas.get (position);} @Overridepublic  long getitemid (int position)  {return position;} @Overridepublic  view getview (int position, view convertview, viewgroup  Parent)  {convertview = layoutinflater.from (mainactivity.this). InFlate (R.layout.item, parent, false); String data = mdatas.get (position);mtv =  (TextView)  convertview.findviewbyid ( r.id.tv); Mtv.settext (data); return convertview;}}}


The layout is simple:

<android.support.v4.widget.swiperefreshlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    xmlns:tools=" Http://schemas.android.com/tools "    android: Id= "@+id/swiperefresh"     android:layout_width= "Match_parent"      android:layout_height= "Match_parent"  >    <GridView         android:id= "@+id/gv"         android:layout_ Width= "Wrap_content"         android:layout_height= "Wrap_content"          android:horizontalspacing= "1DP"          android:padding= "20DP"  />    <!--          <listview        android:id= "@+id/lv"        &nbSp; android:layout_width= "Fill_parent"         android:layout_ height= "Fill_parent"  />    --></android.support.v4.widget.swiperefreshlayout >


This article is from the "Blacktao" blog, make sure to keep this source http://blacktao.blog.51cto.com/8456396/1585283

Android logs: Google official drop-down refresh control

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.