B4A Library AHSwipeToRefresh - Wrapper for Android SwipeToRefresh implementation

With the v19.1 version of the Android support library Google added a SwipeToRefresh view to the android system. This is usable with API version 4 and up but it needs the android-support-v4.jar library.

Google uses two different implementations of the SwipeToRefresh usepattern in their own apps. This one is similar to the "Google Now" implementation. Nearly all other Google apps use another (in my opinion slightly nicer) solution but the Google Now version is, what made it into the official Android SDK.

Usage:
Add the AHSwipeToRefresh Object to the activity. This can be done manually or with the designer as a custom view.
Then you have to add a view to the AHSwipeToRefresh object which then can be pulled to start the refresh process. You can only add one single view to the AHSwipeToRefresh object. This should be something like a ListView or ScrollView.
When the user starts a refresh process the "Refresh" event is fired where you can start your refresh process (like loading some data over the net). When the refresh process is complete just set the Refresh property to false to stop the animation.

Installation:
Copy the AHSwipeToRefresh.jar and AHSwipeToRefresh.xml files to your custom libraries folder.

Additionally you will need the android-support-v4.jar. Check with the Android SDK Manager if you have the latest Android Support Library (You will need at least v22) installed. You can find the library in the <SDK_HOME>\extras\android\support\v4 folder. Copy the library to your custom libraries folder.

History:
V1.00
- Initial version

V1.10
- Requires Support Library v22 or up
- Fixed problems with UltimateListView (hopefully, simple example provided)
- Added ability to change background color of the progress indicator
- Added ability to set any number of colors for the progress indicator
- Supports a larger progress indicator
- New event (STR_CanChildScrollUp) to determine when a swipe event should be triggered or not.
- Support for multiple views (See example)
- Added method to set the offset (position) of the progress indicator
 

Attachments

  • AHSwipeToRefreshExample.zip
    13.2 KB · Views: 488
  • AHSwipeToRefreshULVExample.zip
    11.8 KB · Views: 364
  • AHSwipeToRefreshMultiExample.zip
    12.2 KB · Views: 393
  • AHSwipeToRefresh1_10.zip
    13.8 KB · Views: 612
  • ViewPagerSwipeToRefreshExample.zip
    12.4 KB · Views: 404
Last edited:

DonManfred

Expert
Licensed User

eps

Expert
Licensed User
I have created a small project that I have shared in the forum in Spanish, maybe it will be useful.

https://www.b4x.com/android/forum/threads/b4a-generar-una-lista-v0-2-librerías-customlistview-cardview-ahswipetorefresh.81739/

Muchas gracias (many thanks!) both

I'll check it out and let you know how I get on :)

....

The above didn't work for me either, but it did lead me to a solution :)

I've removed the PC and VP stuff (see Donmanfred's post) and this now 'works' well at least it displays something! :) now to get the functionality working that I wanted to in the first place... :)
 

yiankos1

Active Member
Licensed User
Good morning,
I use it with ULV but as another user mention here, object scrolls down but it does not animate till async finishes. It disappears immediately. At your example, with timer, everything works fine.
 

rscheel

Well-Known Member
Licensed User
Good morning,
I use it with ULV but as another user mention here, object scrolls down but it does not animate till async finishes. It disappears immediately. At your example, with timer, everything works fine.

B4X:
Sub STR_Refresh
    Log("Refresh started")
    tm.Initialize("Timer", 2000)
    tm.Enabled = True
    STR.Enabled = False 'Try changing it to True
End Sub
 

yiankos1

Active Member
Licensed User
B4X:
Sub STR_Refresh
    Log("Refresh started")
    tm.Initialize("Timer", 2000)
    tm.Enabled = True
    STR.Enabled = False 'Try changing it to True
End Sub
You are right. That solved issue! Thank you
 

eps

Expert
Licensed User
I know there is canChildScrollUp but is there an equivalent canChildScrollDown or is the answer to this question 'obvious'?
 

Brandsum

Well-Known Member
Licensed User
You can attach native UIRefreshcontrol to scroll view and table view. The tutorial I have posted is for scroll view. If you want to use this with a table view then click on the original tutorial link from that tutorial.
 
Top