B4A Library [B4X] CLVSwipe - xCustomListView Swipe actions and pull to refresh

Status
Not open for further replies.
CLVSwipe is a class that adds "swipe actions" and pull to refresh features to the standard xCustomListView library.

It is compatible with B4A and B4i (currently not with B4J).
Both features are optional.


Using it is simple:

1. Add the class to your project. It depends on XUI, xCustomListView and ViewsEx v1.30+.
2. Initialize Swipe and pass the CustomListView.
3. In B4i, call Swipe.Resize when the page is resized.

Adding action commands:

- Set the action colors:
B4X:
Swipe.ActionColors = CreateMap("Delete": xui.Color_Red, "Do Something Else": xui.Color_Green, _
       "Action 1": xui.Color_Red, "Action 2": xui.Color_Blue, "Action 3": xui.Color_Yellow)
- Create the items values with Swipe.CreateItemValue:
B4X:
CustomListView1.AddTextItem($"Important item ${i} ..."$, Swipe.CreateItemValue("", Array("Delete", "Do Something Else")))
- Handle the ActionClicked event:
B4X:
Sub Swipe_ActionClicked (Index As Int, ActionText As String)

Pull to refresh:

- Create the PullToRefreshPanel panel. This is the panel that appears when the user pulls the list.
- Set it with Swipe.PullToRefreshPanel.
- Handle the RefreshRequested event. Make sure to call Swipe.RefreshCompleted when done.
- In B4i you need to call Swipe.ScrollChanged from the ScrollChanged event.

B4A and B4i projects are attached. Note that the class module is identical in both projects.

Updates

V1.13 - New ScrollingEnabled property - enables or disables scrolling.
V1.12 - Fixes an issue with the Resize method.
V1.11 - Fixes an issue with horizontal swipes when the list is empty.
v1.10 - Adds pull to refresh feature.

The class is included inside the project.
 

Attachments

  • CLVSwipeExample.zip
    17.9 KB · Views: 1,690
Last edited:

Myr0n

Active Member
Licensed User
Longtime User
Awesome.
Thank you

Is it possible to define Left or Right swipe event independently?
 

Myr0n

Active Member
Licensed User
Longtime User
Ok

Thank you
 

ocalle

Active Member
Licensed User
Longtime User
Great! Thanks by this improvement! , is possible add images next to row data?
 
Last edited:

Yuri Cinesi

Active Member
Licensed User
Amazing work as usual. Would it be possible to have the refresh work even when at the top of the listview?
 

Yuri Cinesi

Active Member
Licensed User
Apologies, I wasn't very clear. I meant that if the user is already at the top of the list (for example they've just opened the app) swiping up does nothing (at least on my device). I was wondering if it would be possible to change that.
 

Eduardo Enri

Member
Licensed User
At least in my case, some layout components as ProgressBar are masked (hidden) by the clv component when Swipe module is initialized. My solution is to use the BringToFront method such that:

B4X:
ProgressBar1.BringToFront

Is there any other more elegant solution?

Thanks in advance!
 

Eduardo Enri

Member
Licensed User
Please upload a small example that demonstrates the issue.

Ok, attachment. It is a simple copy of the original example 'B4A CLVSwipe' that adds a single Progressbar2 component to the main layout.

I have simply included this line of code in the Main activity module:

B4X:
ProgressBar2.BringToFront

It also happens with panels.
 

Attachments

  • Example1.zip
    13.4 KB · Views: 747

Eduardo Enri

Member
Licensed User
This is expected as a new panel is added and CLV is added to the new panel. Your solution looks very elegant to me. You can also send CLVSwipe to the back if you prefer:

Ok.
I prefer your alternative, I think it's simpler.

Thank you.
 
Status
Not open for further replies.
Top