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.

4

1 回答 1

2

您可以扩展 SwipeRefreshLayout,覆盖 onTouchEvent,并对 ACTION_DOWN 事件进行更改,即:

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 以更新操作栏或您想要的任何其他内容......

于 2014-04-29T21:16:02.890 回答