Android的刷卡刷新布局滚动刷新 [英] Android Swipe Refresh Layout scroll up to refresh

查看:89
本文介绍了Android的刷卡刷新布局滚动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个刷卡刷新布局我的网格视图和它完美的作品,如果我拉(滚动)向下的刷新被调用。

I've implemented a swipe refresh layout for my grid view and it works perfectly if I pull (scroll) downwards for the refresh to be called.

不过,我想弄清楚如何刷新用户滚动时的。因此,当用户到达最后的项目在网格(我的极限是10),使用户可以看到所有十下,然后向上拉或试图继续滚动哪能再刷新?

However, I'm trying to figure out how to refresh when the user scrolls up. So when the user reaches the last of the items in the grid (my limit is 10) so when the user sees all ten and then pulls upwards or tries to continue to scroll how can I then refresh?

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

这样的人无论是:不知道这个问题的答案或B:他们不愿​​意分享知识

so people either a: don't know the answer to this question or b: they're not willing to share the knowledge.

很长一段时间我想到了我自己的解决方案后,无论如何。我添加了一个滚动监听到我的网格,当我滚动到屏幕的底部,在这一点上,我记得onRefresh()方法从轻扫刷新计算...

Anyway after a long time I came up with my own solution. I added a scroll listener to my grid, and calculated when I scrolled to the bottom of the screen, at this point I recall the onRefresh() method from the swipe to refresh...

修改
导入更多信息

EDIT to add further info

所以,我做了一些研究之后,计算,当用户达到网格视图底部的我也跟着像<一个问题href=\"http://stackoverflow.com/questions/20276396/android-how-can-i-know-when-gridview-has-reached-the-bottom\">this和其他人得到。下面是我的code,我不得不为了有它的原生功能,令人耳目一新的工作来改变。我的改变是,以prevent不断令人耳目一新。因此,包括在我的if语句是支票,目前未刷新,所以当我到了谷底它刷新,但是我没有这个检查,以便它不断刷新。然后,我不得不这样做对项目的总金额的支票在我的网格,当用户到达的最后一个项目(最后一项)的应用程序也保持清爽,没有什么要打破这种循环。希望这是一些帮助...

So, after I did some research to calculate when the user reached the bottom of a grid view I followed questions like this and others to get that. Below is my code that I had to alter in order have it work with the native refreshing functionality. My alterations were to prevent constant refreshing. So included in my if statement is a check that it's not currently refreshing, so when I reached the bottom it refreshed, but I didn't have that check so it constantly refreshed. I then had to do a check against the total amount of items in my grid, as when the user reached the last item (very last item) the app also kept refreshing and there was nothing to break the cycle. Hopefully this is of some help...

        worldBeersGrid.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }
        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            int position = firstVisibleItem+visibleItemCount;
            int limit = totalItemCount;
            int totalItems = sharedpreferences.getInt("WORLD ITEM COUNT", 0);

            Log.i("TOTAL WORLD ITEMS", String.valueOf(totalItems));
            Log.i("LIMIT :::::::::::: ", String.valueOf(limit));
            Log.i("POSITION ::::::::::::", String.valueOf(position));
            Log.i("REFRESHING :::::::::::::::", String.valueOf(swipeRefreshLayout.isRefreshing()));

            if(position>=limit && totalItemCount>0 && !swipeRefreshLayout.isRefreshing() && position <totalItems){
                swipeRefreshLayout.setRefreshing(true);
                //In the below method I made my call to my ws...
                onRefresh();
            }
        }
    });

这篇关于Android的刷卡刷新布局滚动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆