SwipeRefreshLayout is a pull-down refresh component updated by Google in the support v4 19.1 library, making it easier to refresh.
Use:
1. First download the latest android-support-v4.jar version, the previous version is not SwipeRefreshLayout drop-down refresh control, if updated, this step can be omitted.
2. InXmlFile ReferenceAndroid. support. v4.widget. SwipeRefreshLayoutControls, which can be placed with any controls, such as ListView and gridview.
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_refresh" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" > </ListView> </android.support.v4.widget.SwipeRefreshLayout>
3. Use it in a java file.
/*** Homepage * @ author w. w */public class MainActivity extends Activity implements SwipeRefreshLayout. onRefreshListener {/*** Add a drop-down refresh to the ListView */private SwipeRefreshLayout swipeLayout;/*** ListView */private ListView listView;/*** ListView adapter */private ListViewAdapter adapter; private List <ItemInfo> infoList; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); swipeLayout = (SwipeRefreshLayout) this. findViewById (R. id. swipe_refresh); swipeLayout. setOnRefreshListener (this); // The swipeLayout style refreshed on the top. setColorScheme (android. r. color. holo_red_light, android. r. color. holo_green_light, android. r. color. holo_blue_bright, android. r. color. holo_orange_light); infoList = new ArrayList <ItemInfo> (); ItemInfo info = new ItemInfo (); info. setName ("coin"); infoList. add (info); listView = (ListView) this. findViewById (R. id. listview); adapter = new ListViewAdapter (this, infoList); listView. setAdapter (adapter);} public void onRefresh () {new Handler (). postDelayed (new Runnable () {public void run () {swipeLayout. setRefreshing (false); ItemInfo info = new ItemInfo (); info. setName ("coin-refresh"); infoList. add (info); adapter. notifyDataSetChanged () ;}, 500 );}}
Demo: http://download.csdn.net/detail/xue_wei_love/7135315