And*_*ise 4 android pull-to-refresh
我开发了一个具有一个列表视图的应用程序,我使用Pull来刷新刷新列表数据,同时下拉,所以我在我的代码中完美实现但是当我向上滚动列表向下滚动时我得到一个问题但是当我向下滚动它不滚动完成,因为它考虑拉动刷新和刷新数据但我想在显示列表索引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();
Run Code Online (Sandbox Code Playgroud)
在刷新
@Override
public void onRefresh() {
new GetNotificationList().execute();
}
Run Code Online (Sandbox Code Playgroud)
小智 15
我认为这总是让开发人员感到困惑所以我得到了一些技巧,希望你能提供帮助
第一个覆盖列表视图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);
}
});
Run Code Online (Sandbox Code Playgroud)
然后在第一个可见项为0时设置条件然后滑动启用否则禁用代码,您可以看到..
我希望这个技巧可以帮助你......
| 归档时间: |
|
| 查看次数: |
3344 次 |
| 最近记录: |