Android Question It's probably what I am doing wrong

mrred128

Active Member
Licensed User
Longtime User
I have a panel that I dynamically add listview and checkbox objects on. The panel no longer sees touch events. It did when I used static (designer inserted objects). I use the touch event to decipher swipes for page movement.

The panel event does not even get called and you can select the checkbox. Just not through any control of my program.

These listview and checkbox objects don't actually need to see any events, as I have routines for that functionality.

B4X:
'
' map activity over an amiage
'
Sub MapImage(PicNo As Int)
    If StartX > IV(PicNo).Left AND StartX < (IV(PicNo).Left + IV(PicNo).Width) AND StartY > IV(PicNo).Top AND StartY < (IV(PicNo).Top + IV(PicNo).Height) Then
        If ((Page * 9) + 0) >= PicList.Size Then Return
        Dim pic As Pics = PicList.Get((Page * 9) + PicNo)
        Path = pic.Path & "/" & pic.FName
        TitleBar("Page " & Page & " of " & Pages)
#If debug
        Log("IV(" & (PicNo + 1) & ")")
#End If
        If pic.Checked Then
            pic.Checked = False
        Else
            pic.Checked = True
        End If
        PicList.Set((Page * 9) + PicNo,pic)
        CB(PicNo).Checked = pic.Checked
        BTNClearAll.Enabled = True
        BTNSelectAll.Enabled = True
    End If
End Sub

'
' This takes care of the swipe and click actions over the panel
'
Sub PAN1_Touch (Action As Int, X As Float, Y As Float)
    Dim DifX As Float
    Dim DifY As Float
   
    Select Action
        Case PAN1.ACTION_DOWN
#If debug
            Log("Down")
#End If
            StartX = X
            StartY = Y
        Case PAN1.ACTION_MOVE
            ' we don't care for now
        Case PAN1.ACTION_UP
            DifX = X - StartX
            DifY = Y - StartY
#If debug
            Log("Up")
#End If
            ' we are only concerned with left-right swipes, and clicks
            ' we will require 1/6 of screen for valid swipe
            ' mouse click should not have more than 10 pixs movement
            If Abs(DifX) > (PAN1.Width / 6) Then
#If debug
                Log("good swipe x:" & DifX & " y:" & DifY)
#End If
                    If DifX > 0 Then
                    ' swipe left
                    Page = Page - 1
                    If Page < 0 Then Page = 0
                Else
                    'swipe right
                    Page = Page + 1
                    If Page > Pages Then Page = Pages
                End If
                RedrawPage
            Else If Abs(DifX) < (PAN1.Width / 10) AND Abs(DifY) < (PAN1.Height / 10) Then
                ' we will just see this as a region click
#If debug
                Log("click x:" & StartX & " y:" & StartY)
#End If
                'lets map the pics
                Dim a As Int
                For a = 0 To MaxPics - 1
                    MapImage(a)
                Next
            End If
    End Select
    Return   
End Sub


Sub SetupView
    Dim width As Int = (PAN1.width / 3)
    Dim height As Int = (PAN1.height / 3)
    Dim a As Int
    Dim r As Int = 0
    Dim c As Int = 0
    For a=0 To MaxPics - 1
        If IV(a).IsInitialized = False Then
            ' if the object is NOT intalized, we also need to add it to the view
            IV(a).Initialize("") 
            PAN1.AddView(IV(a),0,0,0,0) ' no values here, as we need to scale the object first
            Scale.ScaleViewDS(IV(a))
        End If
        IV(a).Top = r * (height)
        IV(a).Left = c * (width)
        IV(a).width = width
        IV(a).height = height
        If CB(a).IsInitialized = False Then
            ' if the object is NOT intalized, we also need to add it to the view
            CB(a).Initialize("") 
            PAN1.AddView(CB(a),0,0,0,0) ' no values here, as we need to scale the object first
            Scale.ScaleViewDS(CB(a))
        End If
        CB(a).Top = r * (height)
        CB(a).Left = c * (width)
        CB(a).width = width
        CB(a).height = height
        c = c + 1
        If c = 3 Then
            c = 0
            r = r + 1
        End If
    Next
End Sub

The SetupView routine initializes the ImageView grid and uses two 9x dimensioned arrays added to PAN1. The PAN1_Touch is the event handler that never seems to get called any more.

Thoughts?
 

stevel05

Expert
Licensed User
Longtime User
How have you added and initialized PAN1 ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
And in the designer, the eventname is PAN1 ?
 
Upvote 0

strat

Active Member
Licensed User
Longtime User
If Listeviews cover the panel, they may block Panel's touch events. Try to reduce the size of listviews and check the touch event again.
I have a panel and dynamically created scrollviews. Same error occured and I couldn't find any solution.
 
Upvote 0

mrred128

Active Member
Licensed User
Longtime User
I'm not sure if I solved the problem, but I worked around it. I put a transparent panel on top if it and used the events from there. I'm not sure if it would work with a scroll view.
 
Upvote 0
Top