Implementing a "Swipe" and "Finger Up" listener for Android's SwipeRefreshLayout

Article

TJ Dahunsi

Apr 09 2015 · 1 min

Categories:
design
technology

Android's SwipeRefreshLayout is pretty useful for internet based apps that need to notify a user when a pull to refresh action has occurred. However, if you have a complex view hierarchy that uses a FrameLayout to draw certain items over another, say for example a contextual toolbar, the circular ProgressBar drawn by the SwipeRefreshLayout is obscured and hidden from the user.

A way to fix this is to create a class that extends the SwipeRefreshLayout, and Override the OnTouchEvent. Once overridden, call on the superclass to make sure the widget performs as intended, keep the boolean it returns in a local variable, and handle the motion events which will in turn fire off an interface callback when certain conditions are met.

It's not complicated when presented in code form. The extended class is shown in it's entirety below

https://gist.github.com/tunjid/3ff00ca6bb0a8d27fa3c

,