Android Code Snippet CLVDragger Class with Remove Item for xCustomListView (Two versions)

wes58's class called [B4X][class] CLVDragger - drag to reorder elements allows B4a's xCustomListView class to be able to change the order of its items by dragging them across a Label, as well as add items.
It's a class that can be mentioned perhaps in [B4X] [XUI] xCustomListView - cross-platform CustomListView

I have extended it by adding the function to remove the items one by one when dragging horizontally to the left from a Label
(Now the item is either removed or dragged to a new position)

Maybe it can be improved by putting it in a B4XPage and using views from the XUI Views library, for example.

But you could also:

- edit the multiline text of the Label of each item with a B4XDialog and with a LongClick on the Item, for example

- remember the changes: the order of the items by controlling the order of the texts and the checked states of the CheckBoxes through various lists. For when the device is rotated

- save all data changes to two files from the lists, although it could be saved to a single file using JSON, for example

But I'll post that if anyone is interested.


Please, read the entire thread.

- CLVDragger_RemoveItems and corrections -> Post 1 to 3, and 8
- CLVDragger_Remove_Edit_Swipe and corrections -> Post 4 to7


Dependencies: Reflection, xCustomListView and XUI Views libraries.


I attach the example.

Greetings
 

Attachments

  • CLVDragger_RemoveItems.zip
    9.5 KB · Views: 146
Last edited:

GeoT

Active Member
Licensed User
I'm sorry.
I'm reattaching the example with the small fixes in the Dragger_RemoveItem(Index As Int) event.
We now restore the original color of the item's border if the remove is cancelled, and I removed the redundant view declarations.
 

Attachments

  • CLVDragger_RemoveItems.zip
    9.5 KB · Views: 116

GeoT

Active Member
Licensed User
Although you can also reset the item's border color from the class with

B4X:
pnl.GetView(0).SetColorAndBorder(pnl.Color, 0dip, xui.Color_Black, 0)

Or from Main Activity with

B4X:
Dim item As CLVItem = clv1.GetRawListItem(Index)
Dim p As Panel = item.Panel
'...
Dim cdPanel As ColorDrawable
cdPanel.Initialize2(xui.Color_Transparent,0,0,xui.Color_Black)
p.GetView(0).Background = cdPanel
 
Last edited:

GeoT

Active Member
Licensed User
I am now attaching a variation that allows you to edit or remove an item by swiping left on the Item Label.
This shows an underlying panel with two actions.

Based on the example of Erel [B4X] CLVSwipe - xCustomListView Swipe actions and pull to refresh.

I guess it can be improved and simplified.
I hope it looks like the previous version as well by posting it here.


Greetings
 

Attachments

  • CLVDragger_Remove_Edit_Swipe.zip
    10.7 KB · Views: 110
Last edited:

GeoT

Active Member
Licensed User
Put the same color as in the designer, in the Clv1_ItemClick event, to recover the pressed color of the clicked item:

B4X:
    Dim pnl As B4XView = clv1.GetPanel(Index)
    pnl.SetColorAnimated(700, 0xFF7EB4FA, xui.Color_Transparent)

Cause this property is lost later, I still don't know why
 

GeoT

Active Member
Licensed User
I'm sorry.
I reattach the second version with two small things corrected.

So that two items cannot be dragged, when moving this site code:

B4X:
If LastSwipedItem <> index Then
    Log("LastSwipedItem = " & LastSwipedItem & " and index = " & index)
                
    'We close the previously swiped item
    CloseLastSwiped
End If

And to make the item unable to move to the right past zero when its pnl.Left = 0 with

B4X:
If X > pnl.Left Then Return True
 

Attachments

  • CLVDragger_Remove_Edit_Swipe.zip
    10.8 KB · Views: 126

GeoT

Active Member
Licensed User
And to change the value of the item you have to add this last line

B4X:
Dim p2 As Panel = clv1.GetPanel(Index)
Dim lbl As B4XView = p2.GetView(0)
lbl.Text = "Done!!!"
       
clv1.GetRawListItem(Index).Value = lbl.Text  '<--
 
Last edited:

GeoT

Active Member
Licensed User
For the first example, CLVDragger_RemoveItems, you would add:

B4X:
Sub Process_Globals
    Private LastItemBeingRemoved As Int
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
    'Return to left zero position
    Dim item As CLVItem = clv1.GetRawListItem(LastItemBeingRemoved)
    Dim p As Panel = item.Panel
    p.Left = 0
    
    'We return to establish the original border color
    Dim cdPanel As ColorDrawable
    cdPanel.Initialize2(xui.Color_Transparent,0,0,xui.Color_Black)
    p.GetView(0).Background = cdPanel
End Sub

Sub Dragger_RemoveItem(Index As Int)  
    LastItemBeingRemoved = Index
End Sub

in case we minimize the app or turn off the screen when we are removing an item.
 
Top