Android Question Array of editText

TMourlan

Member
Licensed User
Hello,
I create an activity that contains an array of editText. I saw some examples to know wich editText get the focus but it doesn't work for me...

I create an activity with an array of 10 editText but the 2 sub EditTexts_EnterPressed and EditTexts_FocusChanged doesn't work.
if I click on an editBox, the function EditTexts_FocusChanged is not called.
What am i doing wrong?

Thank you for your help

I post the example :

B4X:
Sub Globals
    Private mainPage As B4XMainPage
    Private EditTexts(10) As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    mainPage = B4XPages.MainPage
    Dim i As Int
    Dim Row As Int

    Row = 10%x
    For i = 0 To 9
        EditTexts(i).Initialize("EditTexts" & i)
        EditTexts(i).tag = i
        EditTexts(i).text = "Blalbla" & i
        EditTexts(i).Gravity = Gravity.CENTER
        Activity.AddView(EditTexts(i),20%x, Row, 20%x, 5%y)
        Row = Row + 5%y
    Next
    mainPage.resizeViews(Activity)

End Sub

Sub EditTexts_EnterPressed
    Dim Row As Int
    Private edt As EditText
    
    edt = Sender
    Row = edt.Tag
End Sub


Sub EditTexts_FocusChanged(HasFocus As Boolean)
    Dim Row As Int
    Private edt As EditText
    Dim Couleur As Int
    
    edt = Sender
    Row = edt.Tag
    If Not (HasFocus) Then
        If Row/2 = Round(Row/2) Then
            Couleur = Colors.White
        Else
            Couleur = Colors.Cyan
        End If
    Else
        Couleur = Colors.Blue
    End If
    EditTexts(Row).Color = Couleur
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
EditTexts(i).Initialize("EditTexts" & i)
This expects to have multiple subs for each of them.
B4X:
EditTexts1_FocusChanged(HasFocus As Boolean)
EditTexts2_FocusChanged(HasFocus As Boolean)
EditTexts3_FocusChanged(HasFocus As Boolean)
EditTexts4_FocusChanged(HasFocus As Boolean)
EditTexts5_FocusChanged(HasFocus As Boolean)
EditTexts6_FocusChanged(HasFocus As Boolean)
EditTexts7_FocusChanged(HasFocus As Boolean)
EditTexts8_FocusChanged(HasFocus As Boolean)
EditTexts9_FocusChanged(HasFocus As Boolean)

ect

I suggest

1. To load the editext with a layout https://www.b4x.com/android/forum/t...ew-here-s-how-to-add-programmatically.118037/
2. Set the Eventname ONLY to "EditTexts" so that each of them is using the same event.
 
Upvote 0
Top