Android Question Moving Labels based on touch event


Active Member
Licensed User
Hello Guys,

I'm working to move labels on the screen based on touch event, but it seems touch it is only available at activity level. Is that true?

I based my research on the ThreeActivityExample.b4a project.
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
    Private dX, dY As Float
    Log("Action " & Action & " X=" & x & " Y=" & Y)
    Select Action                                    ' Selects the Action parameter
        Case Activity.ACTION_DOWN            ' Checks if ACTION_DOWN
            X0 = X                                            ' Memorizes the X coordinate
            Y0 = Y                                            ' Memorizes the Y coordinate
            X1 = lblLetter.Left                        ' Memorizes the Left coordinate
            Y1 = lblLetter.Top                        ' Memorizes the Top coordinate

        Case Activity.ACTION_MOVE            ' Checks if ACTION_MOVE
            dX = X - X0                                    ' Calculates the X distance moved
            dY = Y - Y0                                    ' Calculates the X distance moved
            lblLetter.Left = X1 + dX            ' Sets the new Left coordinate
            lblLetter.Top = Y1 + dY                ' Sets the new Top coordinate
        Case Activity.ACTION_UP                ' Checks if ACTION_UP
            Log("Left " & lblLetter.Left) ' Memorizes Left in the Map
            Log("Top " & lblLetter.Top)     ' Memorizes Top in the Map
            lblCoord.Text = (lblLetter.Left & "-" & lblLetter.Top)

    End Select
End Sub

This code works ok for a single label, but let's say a have 3-4 labels on the screen that I want to move then randomly (one each time). Which approach should I take?



  • APP04
    10 KB · Views: 304

Jorge M A

Well-Known Member
Licensed User
BTW, if you decide to use this approach, you must use the Drag event.
Attached you app whit two labels and GD.
Try it in release mode, and better in real device.


    10.3 KB · Views: 364
Upvote 0