Android Question ScrollView: how to handle touch event?

FrankBerra

Active Member
Licensed User
Longtime User
Hi all,
i am trying to get out from troubles when using touch panels in scrollview.

I have some panels in a scrollview; when i touch panels they change color, when i untouch them the color revert to original state.
Some troubles occours when i touch panels and at the same time i scroll the scrollview but using Scrollview_ScrollChanged everything works almost correctly: if ScrollChanged is fired i revert the color of the panel back to original state.

The real problem occours when i am at the bottom (or at the top) of the scrollview: if i insist to scroll down even if i am at bottom obviously it can't scroll and then Scrollview_ScrollChanged is not called BUT scrollview consumes touch and so i can't revert back the color of the panel.

Is there a trick (or parts of codes) that i can use to handle correctly touch events of panels in a scrollview?

Thanks in advance
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I am not sure I fully understood you but did you try panel_Touch (Action As Int, X As Float, Y As Float) event with Sender keyword ?
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Yes sure

I use the following code:

B4X:
Sub PannelliDatiMappe_Touch (Action As Int, X As Float, Y As Float)
       Dim PannelloToccato As Panel
        PannelloToccato = Sender

        Dim PannellinoToccato As Panel
        PannellinoToccato = Sender
       
        If Action = Activity.ACTION_UP Then

         touchduration = DateTime.Now - touchstart     'Calcola quanto è durato il click
        If touchduration < 400 Then 'Se la durata è minore di 400ms allora è un click
           If (PannellinoToccatoPrecedente.IsInitialized) And (PannellinoToccatoPrecedente <> PannellinoToccato) Then
             PannellinoToccatoPrecedente.color=Colors.White
           End If
           
            PannellinoToccatoPrecedente = PannellinoToccato
           
          Else 'Altrimento è un click lungo
            If (PannellinoToccatoPrecedente.IsInitialized) And (PannellinoToccatoPrecedente <> PannellinoToccato) Then
                PannellinoToccato.color=Colors.White
            End If
          End If
    End If
     
    If Action = Activity.ACTION_DOWN Then   'Salvo il momento in cui il tasto è stato toccato  
          touchstart = DateTime.Now
        
        If (PannellinoToccatoPrecedente.IsInitialized) And (PannellinoToccatoPrecedente <> PannellinoToccato) Then
            PannellinoToccatoPrecedente.color=Colors.White
        End If
        PannelloToccato.Color=Colors.ARGB (255,239,239,239)
        PannellinoToccatoPrecedente = PannellinoToccato
    End If
End Sub


Sub ScrollViewPannelloCentrale3_Scrollchanged(Position As Int)

        PannellinoToccato.Color=Colors.White

End Sub

...and it works almost perfectly but if i am at the bottom (or at the top) of the scrollview and i insist to scroll down the scrollview consumes the touchevent but it doesn't scroll (because i am at the bottom) so the touchevent Scrollview_ScrollChanged is not called and so i can't revert back the color of the panel. It seems like that "Activity.ACTION_UP" is not fired.

Any suggestions on how other programmers deals with this problem?
 
Upvote 0
Top