像 Android Gmail 这样更新监听器
Update Listener Like Android Gmail
我有一个显示 post 的列表视图。
我想要的是当用户向下移动手指并且列表视图无法滚动时的监听器。(就像 Gmail 上的更新监听器 Android 应用程序收件箱,当您从上到下移动手指时它会更新收件箱)。
我该怎么做?
您需要的是 google v4 支持库中的 SwipeRefreshLayout。
为了使用它,您需要将可滚动布局包裹在 <android.support.v4.widget.SwipeRefreshLayout>
标签中。然后,您可以在有人滑动刷新您的 activity
代码时创建一个侦听器
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
....
@Override public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
swipeLayout.setRefreshing(false);
}
}, 5000);
}
可以在 Google 的开发者页面上 on this website, and on this page here 找到更多信息。
我有一个显示 post 的列表视图。 我想要的是当用户向下移动手指并且列表视图无法滚动时的监听器。(就像 Gmail 上的更新监听器 Android 应用程序收件箱,当您从上到下移动手指时它会更新收件箱)。
我该怎么做?
您需要的是 google v4 支持库中的 SwipeRefreshLayout。
为了使用它,您需要将可滚动布局包裹在 <android.support.v4.widget.SwipeRefreshLayout>
标签中。然后,您可以在有人滑动刷新您的 activity
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
....
@Override public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
swipeLayout.setRefreshing(false);
}
}, 5000);
}
可以在 Google 的开发者页面上 on this website, and on this page here 找到更多信息。