我开发了一个具有一个列表视图的应用程序,我使用拉动刷新来刷新列表数据,同时下拉,所以我在我的代码中完美地实现了,但是当我向上滚动列表向下滚动时,但当我向下滚动它时,我遇到一个问题不滚动完成,因为它考虑拉动刷新和刷新数据,但我想在显示列表索引 0 时进行拉动刷新,然后它可以工作拉动刷新
所以请帮我解决这个问题
我的代码是
listNotification = (ListView) rootView.findViewById(R.id.listNotification);
listNotification.setCacheColorHint(0);
swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.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);
if (Global.notifications == null) {
swipeLayout.setRefreshing(true);
new GetNotificationList().execute();
}
LoadNotificationToListView();
刷新时
@Override
public void onRefresh() {
new GetNotificationList().execute();
}
我认为这总是让开发人员感到困惑,所以我得到了一些技巧希望你能帮忙
首先重写 listview setOnScrollListener 方法来获取可见项的索引
ListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (firstVisibleItem == 0) {
swipeLayout.setEnabled(true);
} else swipeLayout.setEnabled(false);
}
});
然后在第一个可见项为 0 时设置条件,然后滑动启用,否则禁用,如代码所示。
我希望这个技巧能帮助你..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)