Hi guys, I'm a new with Basic4Android and have a question.
I need to create 150 labels and 150 EditText, I create it on Runtime and the code is almost this:
B4X:
For i = 0 To 150 -1
'Inicia Agregar un Label
labelx.Initialize("labelx")
labelx.TextSize= 20
labelx.Text="Un label"
pnl_formulario1.AddView(labelx, 30dip, (i*30), 200dip, 25dip)
'Inicia Agregar un Textbox
textbox.Initialize("labelx")
textboxTextSize= 20
textbox.Text="Un Textbox"
pnl_formulario1.AddView(textbox, 30dip, (i*30), 200dip, 25dip)
Next
How can I read the .text value on each editbox to save to a SQLlite Database?
I read from the database and put it on the Label ok, but the problem is to read the textboxes.
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
Dim arrlbl(150) As Label
End Sub
B4X:
For i = 0 To 149
arrlbl(i).Initialize("lbl")
arrlbl(i).TextSize= 20
arrlbl(i).Text="Un label "&i
Activity.AddView(arrlbl(i), 30dip, DipToCurrent(i*30), 200dip, 25dip)
Next
B4X:
Sub Button1_Click
For i = 0 To 149
Log(arrlbl(i).Text)
Next
End Sub
Dim lbl_fromulario1(150)
Dim edt_fromulario1(150)
For i = 0 To 149
lbl_fromulario1(i).Initialize("lbl_fromulario1")
lbl_fromulario1(i).TextSize= 20
lbl_fromulario1(i).Text="Un label"
lbl_fromulario1(i).Tag = i ' only needed if you need events
pnl_formulario1.AddView( lbl_fromulario1(i), 30dip, (i*30dip), 200dip, 25dip)
edt_fromulario1(i).Initialize("edt_fromulario1")
edt_fromulario1(i).TextSize= 20
edt_fromulario1(i).Text="Un label"
edt_fromulario1(i).Tag = i ' only needed if you need events
pnl_formulario1.AddView(edt_fromulario1(i), 130dip, (i*30dip), 200dip, 25dip)
Next
I changed the Label and EditText names like the Panel.
And then
Bobby = lbl_fromulario1(i).Text
edt_fromulario1(i).Text = "anything"
If you need events, then:
B4X:
Sub edt_fromulario1_EnterPressed ' or any other event
Dim edt As EditText
' you can work directly with this EditText object
edt = Sender ' Sender is the EditText which raised the event
SomeVariable = edt.Text
' or wget the index
Dim Index As Int
Index = edt.Tag ' Index of the EditText which raised the event
SomeVariable = edt_fromulario1(Index).Text
' your code
End Sub
Ohh thanks DonManfred, klaus a Lot!!
I'm testing the code and work almost perfect for me.
But in the events I have a problem
B4X:
Dim Calendar As DateDialog
Sub edt_R4_LongClick
calendario.Show ("Seleccione", "Calendario", "OK", "Cancelar", "", Null)
edt_R(4).Text=DateTime.Date(calendario.DateTicks)
End Sub
I try to show a data picker, in Edittext created with the designer work.
I'm afraid that you are mixing up different things:
You use Sub edt_R4_LongClick
and then in the routine you use edt_R(4).
These are not the same !
As said before without seeing what you have done it's impossible to give a concrete advice !
Couldn't you post a small project, as a zip file, showing the problem.
The txt_LongClick event routine should look like this:
B4X:
Sub txt_LongClick
Dim edt As EditText
Dim i As Int
edt = Sender 'Sender is the view which raised the event
i = edt.Tag 'i = index of the EditText view in the txt array
Calendario1.Show("Seleccione", "Calendario", "OK", "Cancelar", "", Null)
txt(i).Text=DateTime.Date(Calendario1.DateTicks)
End Sub