Android officially provides drop-down refresh controls--swiperefreshlayout

Source: Internet
Author: User

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Tools:context= "Com.example.administrator.mydemo.PullActivity">7     <Android.support.v4.widget.SwipeRefreshLayout8         Android:id= "@+id/mpull"9 Android:layout_height= "Match_parent"Ten Android:layout_width= "Match_parent" One         > A         <ListView -             Android:id= "@+id/mlist" - Android:layout_width= "Match_parent" the Android:layout_height= "Match_parent"> -         </ListView> -  -     </Android.support.v4.widget.SwipeRefreshLayout> +  -  + </Relativelayout>
1 ImportAndroid.os.Handler;2 ImportAndroid.os.Message;3 Importandroid.support.v4.widget.SwipeRefreshLayout;4 Importandroid.support.v7.app.AppCompatActivity;5 ImportAndroid.os.Bundle;6 ImportAndroid.widget.ListView;7 ImportAndroid.widget.SimpleAdapter;8 ImportAndroid.widget.Toast;9 Ten Importjava.util.ArrayList; One ImportJava.util.HashMap; A Importjava.util.List; - ImportJava.util.Map; -  the  Public classPullactivityextendsappcompatactivity { -     Privateswiperefreshlayout swiperefreshlayout; -     PrivateListView ListView; -     Privatelist List; +     PrivateSimpleadapter Simpleadapter; -  + @Override A     protected voidonCreate (Bundle savedinstancestate) { at         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_pull); - Initview (); - setlist (); -     } -  in     Private voidInitview () { -swiperefreshlayout=(swiperefreshlayout) Findviewbyid (r.id.mpull); toSwiperefreshlayout.setonrefreshlistener (NewSwiperefreshlayout.onrefreshlistener () { + @Override -              Public voidOnrefresh () { the                 // *                 NewHandler (). postdelayed (NewThread (NewRunnable () { $ @OverridePanax Notoginseng                      Public voidrun () { -Swiperefreshlayout.setrefreshing (false); the  +                         //send message after refresh AMessage msg=NewMessage (); theMsg.what=1; + mhandle.sendmessage (msg); -  $                     } $}), 3000); -             } -         }); thelistview=(ListView) Findviewbyid (r.id.mlist); -     }Wuyi     PrivateHandler mhandle=NewHandler () { the @Override -          Public voidhandlemessage (Message msg) { Wu             Super. Handlemessage (msg); -             if(msg.what==1){ AboutToast.maketext (Getapplicationcontext (), "Refresh succeeded!" ", Toast.length_short). Show (); $                 //data to be loaded after pull- down -List mlist=NewArrayList (); -                  for(inti=0;i<20;i++){ -Map map=NewHashMap (); AMap.put ("img", r.drawable.img); +Map.put ("Text", "drop-down data" +i); the mlist.add (map); -                 } $ List.addall (mlist); the simpleadapter.notifydatasetchanged (); the             } the         } the     }; -     Private voidsetlist () { inlist=NewArrayList (); the          for(inti=0;i<20;i++){ theMap map=NewHashMap (); AboutMap.put ("img", r.drawable.img); theMap.put ("Text", "New data" +i); the list.add (map); the         } +Simpleadapter=NewSimpleadapter ( This, List,r.layout.list_item,NewString[]{"img", "Text"},New int[]{r.id.my_img,r.id.my_item}]; - Listview.setadapter (simpleadapter); the     }Bayi}

Android officially provides drop-down refresh controls--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.