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.
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....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With