Android Question requesting edittext text when created in loop

Niek Wegman

New Member
Licensed User
Hi there, i have a set of code creating 8 edittext fields in an activity. when a button is pressed i want it to read all the edittext entries, the problem is i've created the textboxes using code with a "for i = 1 to 8" line, which looks like this:

B4X:
    'generating labels and namefields
    For i = 1 To 8
        Dim labelplayer As Label
        labelplayer.initialize("label" & i)
        'changing albel properties
        labelplayer.Text = "Player " & i
        labelplayer.Textsize = 20
        
        
        
        labelplayerYloc = 20%y*i
        labelplayerXloc = 5%x
        'generating second column when Y exceeds 100%
        If labelplayerYloc >= 100%y Then
            labelplayerYloc = labelplayerYloc - 80%y
            labelplayerXloc = 45%x
        End If
        'adding label to view
        Activity.AddView(labelplayer, labelplayerXloc, labelplayerYloc, 100dip, 40dip)
        
        
        'generating namefields
        Dim txtplayer As EditText
        txtplayer.initialize("txt" & i)
        txtplayerYloc = labelplayerYloc
        txtplayerXloc = labelplayerXloc + 100dip
        'adding txt to view
        Activity.AddView(txtplayer, txtplayerXloc, txtplayerYloc, 100dip, 40dip)
    Next
    
    'create start button
    Dim startbutton As Button
    startbutton.Initialize("startbutton")
    startbutton.Text = "start"
    Activity.AddView(startbutton, 80%x, 0, 20%x, 100%y)
how do i make the button read all values inserted in the edittext fields?
 

Niek Wegman

New Member
Licensed User
for anyone wondering, i solved it using this

B4X:
For i = 0 To Activity.NumberOfViews - 1
        If Activity.GetView(i) Is EditText Then
            Dim tekstvak As Label
            tekstvak = Activity.GetView(i)
            Dim naam As String = tekstvak.Text
        End If
    Next
 

MarkusR

Well-Known Member
Licensed User
if you had add them into a list then u do not need to search them.

i wonder why u test is edittext and cast into a label.
 
Top