SwipeRefreshLayout detects scroll down to start onRefresh () start

I want to determine when users pull for updates

(the update line in the ActionBar section begins to expand to the width of the user interface).

I want to replace the ActionBar with a message ("Scroll down to Refresh"), but

I do not know which event should be used to call my function.

+4
source share
1 answer

You can extend SwipeRefreshLayout, override onTouchEvent and make changes to the ACTION_DOWN event, that is:

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

, . , , Runnable setOnActionDown , ....

+2

Source: https://habr.com/ru/post/1538343/


All Articles