Android Question Different action for 3 different buttons

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello,
I created by code 3 buttons, Btn_MyPlay (0), Btn_MyPlay (1), Btn_MyPlay (2), what is the syntax for each button to have a different action:
B4X:
Sub Btn_MyPlay (0) _Click
Play1
End Sub
Sub Btn_MyPlay (1) _Click
Play2
End Sub
Sub Btn_MyPlay (2) _Click
Play2
End Sub
B4X:
Sub  FillScrollGAMMES
    Dim gd1 As GradientDrawable
    Dim gd2, gd4 As GradientDrawable
    Dim cols1(2) As Int
    gd1.Initialize("TOP_BOTTOM",cols1)
    gd1.CornerRadius = 10
    ScrollGammes.Panel.Height = 500dip
    'Met en place les gammes xxxxxxxxxxxxxxxxxxxxxxxxxx
    'Gamme Majeure
    For y = 0 To 2
        Dim P As Panel
        Dim Btn_play As Button
        Dim L1, L2, L5 As Label
    
        P.Initialize("")
        gd1.Initialize("TOP_BOTTOM",cols1)
        gd1.CornerRadius = 10
        P.Background = gd1
        P.Color = Colors.ARGB(255,0,5,96)
        ScrollGammes.Panel.AddView(P,5dip,5dip + y * (120dip + 15dip),90%x,130dip)
        MyPanel(y) = P
    
        L1.Initialize("") ' Gamme majeure etc
        L1.Color = Colors.ARGB(255,0,5,96)
        L1.TextColor = Colors.White
        L1.TextSize= 19
        'P.AddView(L1,5dip,5dip,95dip,35dip)
        P.AddView(L1,40dip,5dip,90%x - 30dip,35dip)
        Mylabel1(y) = L1
        
        
        L2.Initialize("")   'T - T - 1/2T - T - etc
        gd2.Initialize("TOP_BOTTOM",cols1)
        gd2.CornerRadius = 10
        L2.Background = gd2
        L2.Color = Colors.ARGB(255,5,53,211)
        L2.TextColor = Colors.White
        L2.TextSize= 16
        L2.Gravity = Gravity.CENTER_HORIZONTAL
        L2.Text = "T - T - 1/2T - T - T - T - 1/2T"
        P.AddView(L2,5%x,38dip,100%x - 20%x,25dip)
        MyLabel2(y) = L2

        
        L5.Initialize("")   ' 1 - 2 - 3b - 6 - 7
        gd4.Initialize("TOP_BOTTOM",cols1)
        gd4.CornerRadius = 10
        L5.Background = gd4
        L5.Color = Colors.ARGB(255,195,195,195)
        L5.TextColor = Colors.Black
        L5.TextSize= 16
        L5.Typeface = Typeface.DEFAULT_BOLD
        L5.Gravity = Gravity.CENTER_VERTICAL
        L5.Gravity = Gravity.CENTER_HORIZONTAL
        
        P.AddView(L5,5%x,95dip,100%x - 20%x,25dip)
        MyLabel5(y) = L5
        
        Btn_play.Initialize("") ' le bouton Play
        Dim cs As BitmapDrawable
        cs.Initialize(LoadBitmap(File.DirAssets, "play.png"))
        Btn_play.Color =Colors.White
        Btn_play.TextColor = Colors.White
        Btn_play.Background = cs
        
        P.AddView(Btn_play,90%x - 80dip,5dip,60dip,28dip)
        Btn_MyPlay(y) = Btn_play

    Next

End Sub
 

Attachments

  • Essai-Beeper.zip
    10.4 KB · Views: 133
Top