在滚动列表视图中使用“拉到刷新"时出现问题 [英] Issue while scroll List view with Pull to Refresh
问题描述
我已经开发了一个具有一个列表视图的应用程序,并且在下拉时使用Pull刷新刷新列表数据,因此我在代码中实现的很好,但是当我向上滚动列表时却出现一个问题,但是当我向下滚动时向下滚动其未滚动完成,因为它考虑了拉刷新和刷新数据,但是我想在显示列表索引0时使它成功,然后拉动刷新即可
I have develop an application that have one list view and i used Pull to refresh for refresh list data while pull down so i implemented in my code perfectly but i get one issue when i am scroll up list scroll down but when i am scroll down its not scroll done because its consider pull to refresh and refresh data but i want to make it when display list index 0 then it work pull to refresh
所以请帮助我
我的代码是
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();
}
推荐答案
我认为这总是使开发人员感到困惑,所以我得到了一些技巧,希望对您有所帮助
I think this always make confuse to developer so i get some trick for it hope you help
用于获取可见项索引的第一个重写列表视图setOnScrollListener方法
First override list view setOnScrollListener method for geting index of visible item
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时设置条件,然后滑动启用,否则禁用您可以看到的代码.
then set condition while firstvisible item is 0 then swipe enable otherwise disable as code you can see..
我希望这个技巧能对您有所帮助.
i hope this trick help you..
这篇关于在滚动列表视图中使用“拉到刷新"时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!