Android Question Single Click event for many Buttons (SOLVED)

Adie

Member
Licensed User
Longtime User
How do I assign ONE Click event to all the buttons on my popup keyboard? I will use the Tag property to hold the key character or even a 'command' for the action like backspace.

B4X:
Sub btn_Click
    hbGet.Text = hbGet.Text & btn.Tag     ' Add to string
End Sub

The keyboard is a Panel with all the buttons and a Label 'hbGet' with global scope. Once the basics are done it will hopefully be converted to a class.
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Sub btn_Click
    Dim B as Button = Sender
   
    log(b.Tag)     ' Tag
    hbGet.Text = hbGet.Text & b.Tag
End Sub
 
Upvote 0

Adie

Member
Licensed User
Longtime User
Hi, Thanks BUT
I need to assign ONE Click event to many buttons? How does the app know to fire the ONE btn_Click event from the different buttons. Ohhh, the keyboard is designed with the designer so no luck in this code:

btnA.Initialize( "btn_Click")
btnB.Initialize( "btn_Click")
btnC.Initialize( "btn_Click")
...
...

which is what I need (I think?)
Adie
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I don't undestand
 
Upvote 0

Adie

Member
Licensed User
Longtime User
A standard QWERTY keyboard will have more than 40 buttons. In order to process the Click Events there will be 40 Sub's (one for each key) as been created by the designer [Tools] option. In order to simplify the code I would like ALL 40 buttons to fire the same event. (Only the one sub like in your code above.)

The only other way is I know of is to create the whole keyboard in code so I can use the '.Initialize("btn_Click")' as per my sample above method which works 100% but will be a pain to code.
 
Upvote 0

XbNnX_507

Active Member
Licensed User
Longtime User
A standard QWERTY keyboard will have more than 40 buttons. In order to process the Click Events there will be 40 Sub's (one for each key) as been created by the designer [Tools] option. In order to simplify the code I would like ALL 40 buttons to fire the same event. (Only the one sub like in your code above.)

The only other way is I know of is to create the whole keyboard in code so I can use the '.Initialize("btn_Click")' as per my sample above method which works 100% but will be a pain to code.

Open the visual Designer click in the button, in properties change the event name you want.... Do this for all buttons
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I use this code to create a customized header inside a panel:

B4X:
Sub KeyBoard
    PanelKeyboard.RemoveAllViews
    Dim Dist As Int = PanelKeyboard.Width/10
    Dim ButtonWidth As Int = 40dip
    'qwertyuiop
    'asdfghjkl<
    'zxcvbnmX
    Dim S As String = "qwertyuiop" & "asdfghjkl" & Chr(0xF137) & "zxcvbnm" & Chr(0xF014) & Chr(0xF002)
      
    Log(FontAwesone.TypeFace)  '--- insert on design a Button with TypeFace = FontAwesone
    For i=0 To S.Length-1

        Dim B As Button ' or Label
        B.Initialize("btn")
        B.Color=Colors.Black
        B.TextColor=Colors.White
        B.Gravity=Gravity.CENTER
        B.TextSize=18
        ' for special car in FontAwesone
        If S.charat(i)=Chr(0xF137) Or s.CharAt(i)=Chr(0xF014) Or s.CharAt(i)=Chr(0xF002) Then b.Typeface = AnagramWord.Typeface

        B.Text=S.charat(i)
        If i=S.Length-1 Then
            PanelKeyboard.AddView(b,(i Mod 10)*Dist,Floor(i/10)*ButtonWidth+1dip,(Dist*2)-1dip,ButtonWidth-1dip)
        Else
            PanelKeyboard.AddView(b,(i Mod 10)*Dist,Floor(i/10)*ButtonWidth+1dip,Dist-1dip,ButtonWidth-1dip)
        End If
    Next
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should set the EventName parameter in the designer:

SS-2017-10-27_09.09.21.png


(saw @stevel05 post after writing it)
 
Upvote 0
Top