Android Question Drag multiple selected views

angel_

Well-Known Member
Licensed User
Longtime User
I have multiple panels on the screen and I want to select several of them to move simultaneously, any ideas on where to start?

I've seen:

But I can't find the way to include several views in the same event
 

drgottjr

Expert
Licensed User
Longtime User
your create an array of panels which share the same event(s).
to help you identify which panel(s) is/are raising the event(s)
at any given time, you need to:
1) assign a value to each panel's tag property (eg, 1,2,3, etc)
2) use the Sender object in the event(s).

once you know which panel is the "sender", you can refer to its
tag value to learn which panel in the array is raising the event.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim panelarray(4) As Panel
    Dim selected(4) As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim i As Int
    Dim xpos As Float = 0.0
    Dim pwidth As Float = 18%x
    
    For i = 0 To 3
        panelarray(i).Initialize("sharedevent")
        panelarray(i).Tag = i
        Activity.AddView(panelarray(i), xpos, 0%y, pwidth, 10%y)
        xpos = xpos + 20%x
        panelarray(i).Color = Colors.Yellow
    Next
End Sub

Sub sharedevent_Click
    Dim p As Panel = Sender
    Log(p.Tag & " was clicked")
    selected(p.Tag) = True
End Sub

Sub sharedevent_LongClick
    Dim p As Panel = Sender
    Log(p.Tag & " was long-clicked")
    If selected(p.Tag) Then
        Log("we can drag the selected panels")
        Dim sb As StringBuilder
        sb.Initialize
        Dim i As Int
        For i = 0 To selected.Length - 1
            If selected(i) Then
                sb.Append( i ).Append(" ")
            End If
        Next
        sb.Append(CRLF)
        Log("i would be dragging panels: " & sb.ToString)
    Else
        Log("panel " & p.Tag & " was not previously selected.  so no drag at this time.  maybe later")
    End If
End Sub

click on a couple panels to select them.
then long click on one of them. that triggers the dragging of the others. if you long click on an unselected panel, there is no drag
 

Attachments

  • log.png
    log.png
    4.8 KB · Views: 39
Upvote 0
Top