码迷,mamicode.com
首页 > 其他好文 > 详细

SwipeRefreshLayout -- Google官方"下拉刷新"控件

时间:2015-08-29 18:28:20      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

主要方法:

  设置刷新简体器: setOnRefreshListener() --> SwipeRefreshLayout.OnRefreshListener

    1. isRefreshing()

    2setColorSchema()

    3onRefresh()

1. Layout - activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mark.swiperefreshlayoutdemo.MainActivity" >

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        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>

</RelativeLayout>

2. Java - MainActivity.xml

public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {
	private static final int REFRESH_COMPLETE = 0X01;
	private SwipeRefreshLayout mSwipeLayout;
	private ListView mListView;
	private ArrayAdapter<String> mAdapter;
	private List<String> mDatas = new ArrayList<String>(Arrays.asList("Java",
			"Javascript", "C++", "Ruby", "Json", "HTML"));

	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case REFRESH_COMPLETE:
				mDatas.addAll(Arrays.asList("Refresh-1", "Refresh-2", "Refresh-3"));
				mAdapter.notifyDataSetChanged();
				mSwipeLayout.setRefreshing(false);
				break;
			}
		};
	};

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		mListView = (ListView) findViewById(R.id.listView);
		mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);

		mSwipeLayout.setOnRefreshListener(this);
mSwipeLayout.setColorScheme(
                   android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mDatas);
mListView.setAdapter(mAdapter); } public void onRefresh() { mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000); } }

  

  

SwipeRefreshLayout -- Google官方"下拉刷新"控件

标签:

原文地址:http://www.cnblogs.com/mattle/p/4769371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!