6

I want to detect when users are pulling down for refresh

(refresh line in under ActionBar is starting expand to its UI width).

I want to replace ActionBar with message ("Swipe down to Refresh") but,

I don't know which event should I use to call my function.

Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96
  • you can visit this link [Implementation of SwipeRefreshLayout][1] [1]: http://stackoverflow.com/questions/22856754/how-to-adjust-the-swipe-down-distance-in-swiperefreshlayout?rq=1 – Muhammad Usman Ghani Apr 28 '14 at 05:45

1 Answers1

2

You can extend SwipeRefreshLayout, override onTouchEvent, and make your change on the ACTION_DOWN event, ie:

public class MySwipeRefreshLayout extends SwipeRefreshLayout {

    private Runnable onActionDown, onActionUp;

    public MySwipeRefreshLayout(Context context, AttributeSet attributeSet) {
        super(context,attributeSet);
    }

    public void setOnActionDown(Runnable onActionDown) {
        this.onActionDown = onActionDown;
    }

    public void setOnActionUp(Runnable onActionUp) {
        this.onActionUp = onActionUp;
    }

    @Override
    public boolean onTouchEvent (MotionEvent ev) {
        if (ev.getAction() == ev.ACTION_DOWN) {
            if (onActionDown != null) {
                onActionDown.run();
            }
        } else if (ev.getAction() == ev.ACTION_UP) {
            if (onActionUp != null) {
                onActionUp.run();
            }
        }
        return super.onTouchEvent(ev);
    }
 :
 :
}

Make sure you use the extended class in your layout. Then, in your view, you can pass a Runnable to setOnActionDown to update the actionbar or whatever else you want....

goldstei
  • 51
  • 3