Android Question [solved]HowTo add several DraggableViews by code

Discussion in 'Android Questions' started by opus, Nov 19, 2014.

  1. opus

    opus Member Licensed User

    Hi,
    I was able to use a DraggableView if the used View (in my case an ImageView) was added to the designer. What I'm trying to do is to add several DraggableViews by code, however I got stuck.

    My Code so far:
    Code:
    Sub Globals
      
    Dim Cards As List 'shall hold the List of ImageViews
      Dim dvCards As List 'shall hold the List of draggableViews
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layoutMain"'this layout is empty
    Dim i As Int
    Cards.Initialize 
    'initialize the List
    dvCards.Initialize 'initialize the List
    For i =0 To 20
       
    Dim ivCard As ImageView 'declare an ImageView, for each loop a new one!
       ivCard.Initialize("ivCard"'intialize the ImageView
       Cards.Add(ivCard) 'add it to the List
       Dim dvCard As clDraggableView 'declare an DraggableView, for each loop a new one
       dvCards.Initialize(Activity,ivCard)'intialize the DraggableView
       dvCards.Add(dvCard) 'add it to the List
    Next
    End Sub
    The comments show what I tried to do. However I get an error in the line "dvCards.Initialize(Activity,ivCard)" (in German: "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt." my translation: the Object was not set to an object-instance).
    IMHO "Activity" is correctly set (I'm using it in the same way as when using the view that was added in the designer), so it has to be "ivCard", but WHY?
     
    Last edited: Nov 19, 2014
  2. opus

    opus Member Licensed User

    Spelling problem!
    The line "dvCards.Initialize(Activity,ivCard)" should have been "dvCard.Initialize(Activity,ivCard)".
    However the with this change I get an error from within the DraggableView Class.

    The line
    Code:
    Activity.AddView(panel1, v.Left, v.Top, v.Width, v.Height)
    from the .Initialze Sub raises the error "Error occurred on line: 14 (cldraggableview) - java.lang.NullPointerException"
     
  3. opus

    opus Member Licensed User

    I was missing "Activity.AddView(ivCard,..........)"

    -Solved"
     
Loading...
  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