如何为你的应用添加刷卡刷新
确保在依赖项下的应用程序的 build.gradle
文件中添加了以下依赖项:
compile 'com.android.support:support-core-ui:24.2.0'
然后在布局中添加 SwipeRefreshLayout
:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- place your view here -->
</android.support.v4.widget.SwipeRefreshLayout>
最后实现 SwipeRefreshLayout.OnRefreshListener
监听器。
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
// your code
}
});