标签:
1 <android.support.v4.widget.SwipeRefreshLayout 2 xmlns:android="http://schemas.android.com/apk/res/android" 3 android:id="@+id/swipe_container" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" > 6 <ListView 7 android:id="@+id/listview" 8 android:layout_width="match_parent" 9 android:layout_height="wrap_content" 10 android:padding="16dp" /> 11 </android.support.v4.widget.SwipeRefreshLayout
3 import java.util.ArrayList; 4 import android.app.Activity; 5 import android.os.Bundle; 6 import android.os.Handler; 7 import android.support.v4.widget.SwipeRefreshLayout; 8 import android.widget.ArrayAdapter; 9 import android.widget.ListView; 10 11 public class MainActivity extends Activity implements 12 SwipeRefreshLayout.OnRefreshListener { 13 14 private SwipeRefreshLayout mSwipeLayout; 15 private ListView mListView; 16 private ArrayList<String> list = new ArrayList<String>(); 17 18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_main); 21 22 mListView = (ListView) findViewById(R.id.listview); 23 mListView.setAdapter(new ArrayAdapter<String>(this, 24 android.R.layout.simple_list_item_1, 25 getData()) 26 ); 27 28 mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); 29 mSwipeLayout.setOnRefreshListener(this); 30 // 转动圈的随机颜色 31 mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, 32 android.R.color.holo_green_light, android.R.color.holo_orange_light, 33 android.R.color.holo_red_light); 34 } 35 36 private ArrayList<String> getData() { 37 list.add("Hello"); 38 list.add("This is stormzhang"); 39 list.add("An Android Developer"); 40 list.add("Love Open Source"); 41 list.add("My GitHub: stormzhang"); 42 list.add("weibo: googdev"); 43 return list; 44 } 45 46 public void onRefresh() { 47 new Handler().postDelayed(new Runnable() { 48 @Override 49 public void run() { 50 mSwipeLayout.setRefreshing(false); 51 } 52 }, 5000); 53 } 54 }
1、Android自己的下拉刷新SwipeRefreshLayout
标签:
原文地址:http://www.cnblogs.com/androidsj/p/5234417.html