vsvydenko
vsvydenko

Reputation: 727

How to disable pulltorefresh functionality for first time?

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?

Upvotes: 6

Views: 6403

Answers (4)

Clairton Luz
Clairton Luz

Reputation: 2354

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;
                }
            });

Upvotes: 0

medhdj
medhdj

Reputation: 1178

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

Upvotes: -1

ceram1
ceram1

Reputation: 525

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);

Upvotes: 17

Harshit Rathi
Harshit Rathi

Reputation: 1862

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

Upvotes: 1

Related Questions