Android Question SetOnTouchListener Helper

Douglas Farias

Expert
Licensed User
Longtime User
Sorry for this question again, i need help with this app :(

my problem is

how can i fix this error
-When you press a button = instrument and hold this button you cant press another button = Instrument.

here is my app http://www.b4x.com/android/forum/threads/bateria-drum.39283/
you can download and test, press one button and hold this button, you can not press another in this time, only when you drop.

how can i fix this? i cant play 2 or 3 instruments in same time because this =(

the problem i think is here

B4X:
Sub P1_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
        sp.Play(d1 ,1,1,2,0,1 )
        Return True
    End If
End Sub

but i dont know to fix

here is my app code simple with help of @stevel05
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Gest As Gestures
    Private Panel1,Panel2,Panel3,Panel4,Panel5,Panel6,Panel7,Panel8,Panel9,Panel10 As Panel
    Dim d1,d2,d3,d4,d5,d6,d7,d8,d9,d10 As Int
    Dim sp As SoundPool
    End Sub

Sub Activity_Create(FirstTime As Boolean)
 
     Activity.LoadLayout("1")
    Gest.SetOnTouchListener(Panel1,"P1_Gest")
    Gest.SetOnTouchListener(Panel2,"P2_Gest")
    Gest.SetOnTouchListener(Panel3,"P3_Gest")
    Gest.SetOnTouchListener(Panel4,"P4_Gest")
    Gest.SetOnTouchListener(Panel5,"P5_Gest")
    Gest.SetOnTouchListener(Panel6,"P6_Gest")
    Gest.SetOnTouchListener(Panel7,"P7_Gest")
    Gest.SetOnTouchListener(Panel8,"P8_Gest")
    Gest.SetOnTouchListener(Panel9,"P9_Gest")
    Gest.SetOnTouchListener(Panel10,"P10_Gest")
    sp.Initialize(1000)
  
    d1 = sp.Load(File.DirAssets, "1.mp3")
    d2 = sp.Load(File.DirAssets, "2.mp3" )
    d3 = sp.Load(File.DirAssets, "3.mp3" )
    d4 = sp.Load(File.DirAssets, "4.mp3" )
    d5 = sp.Load(File.DirAssets, "5.mp3" )
    d6 = sp.Load(File.DirAssets, "6.mp3" )
    d7 = sp.Load(File.DirAssets, "7.mp3" )
    d8 = sp.Load(File.DirAssets, "8.mp3" )
    d9 = sp.Load(File.DirAssets, "9.mp3" )
    d10 = sp.Load(File.DirAssets, "10.mp3" )
      
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub P1_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
        sp.Play(d1 ,1,1,2,0,1 )
        Return True
    End If
End Sub
Sub P2_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d2 ,1,1,2,0,1 )
        Return True
    End If
End Sub
Sub P3_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d3 ,1,1,2,0,1 )
        Return True
    End If
End Sub

Sub P4_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d4 ,1,1,2,0,1 )
        Return True
    End If
End Sub

Sub P5_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d5 ,1,1,2,0,1 )
        Return True
    End If
End Sub


Sub P6_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d6 ,1,1,2,0,1 )
        Return True
    End If
End Sub


Sub P7_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d7 ,1,1,2,0,1 )
        Return True
    End If
End Sub


Sub P8_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d8 ,1,1,2,0,1 )
        Return True
    End If
End Sub



Sub P9_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d9 ,1,1,2,0,1 )
        Return True
    End If
End Sub


Sub P10_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
    sp.Play(d10 ,1,1,2,0,1 )
        Return True
    End If
End Sub

Sub Activity_KeyPress(KeyCode As Int) As Boolean
  If KeyCode = KeyCodes.KEYCODE_BACK Then
  AdBox.Visible = True
    Activity.OpenMenu
    Return True
  
Else If KeyCode = KeyCodes.KEYCODE_MENU Then
    AdBox.Visible = True
    Activity.OpenMenu
    Return True
  End If
End Sub


Sub bMenu_Click
      Dim KC As Int
      KC = KeyCodes.KEYCODE_MENU
      Activity_KeyPress (KC)  
End Sub
 

Douglas Farias

Expert
Licensed User
Longtime User
dont have a way to make only click? cany hold button? when you hold it return null for you press another button?

this exemple works fine with play instruments in diferent time, but when you hold button you cant play anoter instrument, i need make a gesture click and no touch have a way?
with click i think it go work because click you cant hold button *-*
 
Upvote 0
Top