Android Question How to create a button that can input text in an edittext

cayahm

New Member
Hello people of the world I was just curious if there is a way to make a button that can input a text on a selected edittext? like if I have a set of buttons which are numbered from 0-9 and there are multiple edittext. Is there a way to select an edittext and by pressing the button the number will show only to that specified edittext?
 

aeric

Expert
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
    Private EditText1 As EditText
    Private EditText2 As EditText
    Private EditText3 As EditText
    Private FocusOn As String = "EditText1"
End Sub

Public Sub Initialize

End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub EditText1_FocusChanged (HasFocus As Boolean)
    If HasFocus Then FocusOn = "EditText1"
End Sub

Private Sub EditText2_FocusChanged (HasFocus As Boolean)
    If HasFocus Then FocusOn = "EditText2"
End Sub

Private Sub EditText3_FocusChanged (HasFocus As Boolean)
    If HasFocus Then FocusOn = "EditText3"
End Sub

Private Sub Button1_Click
    EnterValue("1")
End Sub

Private Sub Button2_Click
    EnterValue("2")
End Sub

Private Sub Button3_Click
    EnterValue("3")
End Sub

Private Sub EnterValue (Value As String)
    Select FocusOn
        Case "EditText3"
            EditText3.Text = EditText3.Text & Value
            EditText3.SetSelection(EditText3.Text.Length, 0)
        Case "EditText2"
            EditText2.Text = EditText2.Text & Value
            EditText2.SetSelection(EditText2.Text.Length, 0)
        Case "EditText1"
            EditText1.Text = EditText1.Text & Value
            EditText1.SetSelection(EditText1.Text.Length, 0)
    End Select
End Sub
 

Attachments

  • MultiEditText.zip
    14.3 KB · Views: 141
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
Here is my simple solution that has been tested. test app attached buttonedittext.jpg
B4X:
Private Sub Button_Click
    Dim btn As Button=Sender
    Log(btn.text)
    btnNum=btn.text
   
    Select chkNum
        Case 1'checkbox1
            EditText1.Text=EditText1.Text & btnNum
        Case 2'checkbox2
            EditText2.Text=EditText2.Text & btnNum
        Case 3'checkbox3
            EditText3.Text=EditText3.Text & btnNum
    End Select
End Sub

Private Sub RadioButton_CheckedChange(Checked As Boolean)
    Dim rb As RadioButton=Sender
    chkNum=rb.Tag
End Sub
 

Attachments

  • button2textEdit.zip
    15 KB · Views: 143
Upvote 0

cayahm

New Member
Thank you everyone I am grateful for all the answers!!! I've finally found a way to make it work thanks I've tried everything you guys sent and they worked thank you so much!
 
Upvote 0
Top