No, you cannot. The Touch event is consumed by the ScrollView!I can handle it to ScrollView.panel
Sub Globals
Private scvTest As ScrollView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
Private ref As Reflector
ref.Target = scvTest
ref.SetOnTouchListener("scvTouchRef")
FillScrollView
End Sub
Private Sub FillScrollView
Private i As Int
Private Height0, Height1 As Int
Height0 = 40dip
Height1 = Height0 - 2dip
For i = 0 To 50
Private lbl As Label
lbl.Initialize("Labels")
scvTest.Panel.AddView(lbl, 0, i * Height0, scvTest.Width, Height1)
lbl.Color = Colors.Blue
lbl.TextColor = Colors.Yellow
lbl.Text = "Test " & i
lbl.Tag = i
Next
scvTest.Panel.Height = i * Height0
End Sub
Private Sub scvTouchRef(Viewtag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
Select Action
Case Activity.ACTION_DOWN
Log("DOWN")
Case Activity.ACTION_MOVE
Log("MOVE")
Case Activity.ACTION_UP
Log("UP")
End Select
End Sub
Private Sub Labels_Click
Private lbl As Label
lbl = Sender
Log(lbl.Text)
End Sub
Thanks Klaus, it works, but, how can I resend the event to scrollview to make it scroll. The scroll stop working with this codeNo, you cannot. The Touch event is consumed by the ScrollView!
But, you can add a Touch event to the ScrollView with the Reflection library.
Attached a small test program.
And the code:
B4X:Sub Globals Private scvTest As ScrollView End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Main") Private ref As Reflector ref.Target = scvTest ref.SetOnTouchListener("scvTouchRef") FillScrollView End Sub Private Sub FillScrollView Private i As Int Private Height0, Height1 As Int Height0 = 40dip Height1 = Height0 - 2dip For i = 0 To 50 Private lbl As Label lbl.Initialize("Labels") scvTest.Panel.AddView(lbl, 0, i * Height0, scvTest.Width, Height1) lbl.Color = Colors.Blue lbl.TextColor = Colors.Yellow lbl.Text = "Test " & i lbl.Tag = i Next scvTest.Panel.Height = i * Height0 End Sub Private Sub scvTouchRef(Viewtag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean Select Action Case Activity.ACTION_DOWN Log("DOWN") Case Activity.ACTION_MOVE Log("MOVE") Case Activity.ACTION_UP Log("UP") End Select End Sub Private Sub Labels_Click Private lbl As Label lbl = Sender Log(lbl.Text) End Sub
I found the solution. Simply "return false" at the end of the fired touch eventThanks Klaus, it works, but, how can I resend the event to scrollview to make it scroll. The scroll stop working with this code