【问题标题】:Issue while scroll List view with Pull to Refresh使用 Pull to Refresh 滚动列表视图时出现问题
【发布时间】:2014-08-25 11:32:20
【问题描述】:

我开发了一个具有一个列表视图的应用程序,并且我在下拉时使用 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();

刷新

 @Override
public void onRefresh() {

    new GetNotificationList().execute();
}

【问题讨论】:

    标签: android pull-to-refresh


    【解决方案1】:

    我认为这总是让开发人员感到困惑,所以我得到了一些技巧希望你能帮助

    第一个覆盖列表视图 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 时设置条件,然后滑动启用,否则禁用代码,您可以看到..

    我希望这个技巧对你有所帮助..

    【讨论】:

    • 如何在回收站列表中修复它?
    • 在滚动视图中拉动刷新是否有等效的修复方法
    猜你喜欢
    • 2014-05-11
    • 2013-02-28
    • 2021-03-17
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    相关资源
    最近更新 更多