6

I'm using chrisbanes's Android-PullToRefresh in my app.

I need to disable pulltorefresh functionality for first time fragment launch - when list is empty and items are downloading in background. In this case (list is empty) user can swipe down and progressbar with "Release to refresh" will shown.

After loading all items I want to enable pulltorefresh functionality..

How?

vsvydenko
  • 729
  • 1
  • 9
  • 22

4 Answers4

17

I had same problem.

According to source, if view is disabled, it'll not eat touch event.

https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/library/src/uk/co/senab/actionbarpulltorefresh/library/PullToRefreshLayout.java#L137

simply, you can do

mPullToRefreshLayout.setEnabled(false);
ceram1
  • 515
  • 1
  • 6
  • 19
1

By default you disable pull to refresh and enable in asyncTask of post execute when to fill adapter of list.

Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25
  • For first time of fragment start, listview is empty. When fragment launches first time, it starts load data in async task. In this moment(list is empty) user can swipe down and show progressbar and text "Release to refresh"(standart header for pulltorefreshlistview). I don't need this header in this case. I need to show this header after loading items.. the user should not be able to pull to refresh until the first page is loaded – vsvydenko Nov 26 '13 at 13:17
  • but why are you not disable by default pulltorefresh or make visibility gone. – Harshit Rathi Nov 26 '13 at 13:21
0

You could put a count and call the method to refresh only when this count is bigger than 0(zero) and set a listener on scroll event to set count to 0(zero), so everytime that the user scroll you list, the count will be set to 0(zero) and when the list arrive on the top and scroll up again you refresh method will be called.

mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    if (countDelay > 0) {
                        countDelay = 0;
                        refresh();
                    } else {
                        mSwipeRefreshLayout.setRefreshing(false);
                        countDelay++;
                    }
                }
            });
mSwipeRefreshLayout.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    countDelay = 0;
                }
            });
Clairton Luz
  • 2,116
  • 19
  • 15
-1

hope this help someone with the same issue:

mRefreshableListView.setMode(PullToRefreshBase.Mode.DISABLED);//to disable the pull functionality
mRefreshableListView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);//or whatever you want
medhdj
  • 1,168
  • 10
  • 17