下拉刷新view

来源:互联网 发布:淘宝偷图会有什么后果 编辑:程序博客网 时间:2024/05/22 19:49

SwipeRefreshLayout 是V.4包支持的一个view所以必须导入V.4包
还有SwipeRefreshLaout的里面必须只能有一个view如果要放其他的view必须放到它的外面

<LinearLayout 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" android:orientation="vertical" tools:context=".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></LinearLayout>

MainActivity

public class MainActivity extends Activity {    private SwipeRefreshLayout mSwipeRefresh;    private ListView mListView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mListView= (ListView) findViewById(R.id.listview);        mSwipeRefresh= (SwipeRefreshLayout) findViewById(R.id.swiperefreshlayout);        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,new String[]{"a","b","c","d","e","f","g","h"});        mListView.setAdapter(adapter);        mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {            @Override            public void onRefresh() {                //当为false是下拉刷新会消失,当为true是一直在下拉刷新                mSwipeRefresh.setRefreshing(true);            }        });    }}
0 0
原创粉丝点击