Android Question DraggableView Class help

Discussion in 'Android Questions' started by rfresh, Apr 24, 2018.

  1. rfresh

    rfresh Well-Known Member Licensed User

    I'm trying to get the DraggableView example to work.

    I'm getting an error: unknown type draggableview

    As the attachment shows, I have the Reflection Lib checked.

    #Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
    #End Region

    'Main activity module
    Sub process_globals

    End Sub

    Sub Globals
    Dim Button1 As Button
    Dim Button2 As Button
    Dim EditText1 As EditText
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    Dim dv1, dv2, dv3 As DraggableView '<---- error on this line
        dv1.Initialize(Activity, Button1)
    Activity, Button2)
    Activity, EditText1)
    End Sub

    'DraggableView class module
    Sub Class_Globals
    Private innerView As View
    Private panel1 As Panel
    Private downx, downy As Int
    End Sub

    Sub Initialize(Activity As Activity, v As View)
        innerView = v
        panel1.Color = 
    Activity.AddView(panel1, v.Left, v.Top, v.Width, v.Height)
        ACTION_DOWN = 
        ACTION_MOVE = 
        ACTION_UP = 
    Dim r As Reflector
        r.Target = panel1
    "Panel1_Touch"'why reflection instead of the regular Panel_Touch event? Good question which deserves a forum thread of its own (not related to classes)...
    End Sub

    Private Sub Panel1_Touch (o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
            downx = x
            downy = y
            innerView.Left = innerView.Left + x - downx
            innerView.Top = innerView.Top + y - downy
            panel1.Left = innerView.Left
            panel1.Top = innerView.Top
    End If
    Return True
    End Sub

    Attached Files:

  2. LucaMs

    LucaMs Expert Licensed User

    DraggableView is a class. You must create a class named DraggleView and move all the code you have after the asterisks to this class (empty the new class before)
  3. rfresh

    rfresh Well-Known Member Licensed User

    I've looked around here and on Youtube but I cannot find any examples of how that is done. There is a lot of discussions about classes and Erel has a tutorial but he doesn't talk about how you actually setup your files and class structure. He talks about modules and classes but gives no full examples that I can find.

    Do I create a separate file? If yes, how do I reference it in my main file?

    Thank you...
  4. LucaMs

    LucaMs Expert Licensed User

    Simply the code you found was not posted in separated blocks!

    This one is the Main (activity module):

    This one is a class:

    Create a new class:

    Name it: "DraggableView".

    Delete all its (default) code.

    Cut (from your project) the class code and paste it to the new class.
  5. rfresh

    rfresh Well-Known Member Licensed User

    Thank you...
  6. rfresh

    rfresh Well-Known Member Licensed User

    Unless I'm mistaken, Button1 and Button2 should be movable like the TextEdit1 object is, but I can't move either button with my finger on my phone screen. I can touch EditText1 and move it around the screen but not the buttons.

    Attached Files:

  7. LucaMs

    LucaMs Expert Licensed User

    Tested your project:
    I can move all the three views (how do you distinguish them? :) - write something).

    Anyway, try to move:

    Dim dv1, dv2, dv3 As DraggableView

    to the Sub Globals.
    Last edited: Apr 24, 2018
  8. rfresh

    rfresh Well-Known Member Licensed User

    Hmmm...I did those two things but still no go. I can't move the buttons. I'm using the B4A IDE if that makes any difference.

    Attached Files:

  9. LucaMs

    LucaMs Expert Licensed User


    I changed... nothing!
  10. LucaMs

    LucaMs Expert Licensed User

    Are you testing your project on a real device? What device?
  11. rfresh

    rfresh Well-Known Member Licensed User

    I'm testing on my phone an LG V20 and I'm testing on the 6 inch screen emulator.

    Yes, I see it's working fine for you. Well, thanks for the help...I'll keep playing around with it and see if I can figure out how to get it working.
  12. LucaMs

    LucaMs Expert Licensed User

    Android 7... now I try on a device with the same S.O. ...
  13. LucaMs

    LucaMs Expert Licensed User

    Tried and I see different things! (buttons over panels).

    Have to check the source code...

    most likely it is due to the elevation of panels.
  14. LucaMs

    LucaMs Expert Licensed User

    1) restore:
    panel1.Color = Colors.Transparent

    2) write:
    panel1.Elevation = 4dip
    ACTION_UP = Activity.ACTION_UP

    in the DraggableView class.
    avalle, Multiverse app and Erel like this.
  15. avalle

    avalle Active Member Licensed User

    I had the same issue. The elevation value solved the issue thanks!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice