Android Question [Solved]CLVDragger

Theera

Well-Known Member
Licensed User
Longtime User
Hello all,
I have studied formbuilder project and interested in CLVDragger.bas . I have tried to code a new project in B4XPages which is attached.
I have 2 problems
B4X:
#If B4J 
Private Sub Drag_MousePressed (EventData As MouseEvent)
#Else
       ???
#End If
    Dim lbl As B4XView = Sender
    Dim list As CustomListView = lbl.Tag
    Dim pnl As B4XView = list.GetPanel(list.GetItemFromView(lbl)).Parent
    pnl.GetView(0).SetColorAndBorder(xui.Color_Transparent, 3dip, 0xFF503ACD, 0)
    Dim ListStartY As Int = EventData.Y + lbl.Top + pnl.Top
    pnl.BringToFront
    Dim Top As Int = pnl.Top
    Do While True
     #If B4J
        Wait For (lbl) Drag_MouseDragged (EventData As MouseEvent)
     #Else
           ???
     #End If
        If pnl.Top < list.sv.ScrollViewOffsetY Then
            list.sv.ScrollViewOffsetY = Max(0, list.sv.ScrollViewOffsetY - 10dip)
        Else If list.sv.ScrollViewOffsetY + list.sv.Height < pnl.Top + pnl.Height Then
            list.sv.ScrollViewOffsetY = list.sv.ScrollViewOffsetY + 10dip
        End If
        Dim ListY As Int = EventData.Y + lbl.Top + pnl.Top
        Dim delta As Int = ListY - ListStartY
        pnl.Top = Top + delta
    Loop
End Sub
#If B4J
Private Sub Drag_MouseReleased (EventData As MouseEvent)
#Else
     ???
#End If
    Dim lbl As B4XView = Sender
    Dim list As CustomListView = lbl.Tag
    Dim index As Int = list.GetItemFromView(lbl)
    Dim pnl As B4XView = list.GetPanel(index).Parent
    Dim Offset As Int = pnl.Top + pnl.Height / 2
    Dim NewIndex As Int = list.FindIndexFromOffset(Offset)
    Dim UnderlyingItem As CLVItem = list.GetRawListItem(NewIndex)
    If Offset - UnderlyingItem.Offset > UnderlyingItem.Size / 2 Then NewIndex = NewIndex + 1
    Dim ActualItem As B4XView = pnl.GetView(0)
    ActualItem.SetColorAndBorder(pnl.Color, 0dip, xui.Color_Black, 0)
    Dim RawItem As CLVItem = list.GetRawListItem(index)
    list.RemoveAt(index)
    If NewIndex > index Then NewIndex = NewIndex - 1
    NewIndex = Max(0, Min(list.Size, NewIndex))
    list.InsertAt(NewIndex, ActualItem, RawItem.Value)
    list.GetRawListItem(NewIndex).TextItem = RawItem.TextItem
End Sub

And another problem when I tested in B4J ,Why it can not be swapped correctly.
 

Attachments

  • DragCell_ItemInCLV.zip
    20.9 KB · Views: 17
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
I have a modified version that worked on B4A, B4i and B4J.
Will it be a part of xCustomListview library, won't it?
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Here it is for you (and all).
Is there example for studying? I think it be useful for Thai programmers'studying.I willadd inThai forum, too.I hope Thaiprogrammers will be interested B4X as powered tools.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Is there example for studying? I think it be useful for Thai programmers'studying.I willadd inThai forum, too.I hope Thaiprogrammers will be interested B4X as powered tools.
Try add the class to your project that you attached above.

Comment the following section:
B4X:
Public Sub AddDragButtons
    list.PressedColor = xui.Color_Transparent
    Dim fnt As B4XFont = xui.CreateMaterialIcons(30)
    For i = 0 To list.Size - 1
        Dim p As B4XView = list.GetPanel(i)
        #Region B4XTodo
        'Dim pnl As B4XView = p.GetView(0)        ' pnlItem
        'Dim btn1 As B4XView = pnl.GetView(2)     ' lblEdit
        'Dim btn2 As B4XView = pnl.GetView(3)     ' lblDelete
        'btn1.Visible = False
        'btn2.Visible = False
        #End Region

Edit: Remember to remove the old class in your B4A folder. You can add this class to the project parent folder (same level as B4XMainPage.bas).
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
If my solution works, please Remember to mark my answer as solution.
1728552577890.png
 
Upvote 0
Top