I may be taking the wrong approach, but I am lost on this. I have the scroll view working, but want to collect the edtField.text values so I can send them off to the database. See the end of the code.
How do I get "foo" to be the input from the edit text field? Is my approach to this incorrect?
Thanks,
Patrick
B4X:
sub globals
Dim edtField As EditText
Dim EditList As List
End Sub
Sub AddScrollViewToDisplay
Dim ScrollViewMain As ScrollView
Dim PanelNb As Int : PanelNb=20
Dim PanelHeight As Int : PanelHeight=50dip
Dim DBFields As List
Dim i As Int
DBFields.Initialize
DBFields.AddAll(Array As String("Category","Sub Category","Time Increment"))
'Insert at the first record the title for the page
DBFields.InsertAt(0, "Add New Record")
ScrollViewMain.Initialize(500)
Activity.AddView(ScrollViewMain, 0, 0, 100%x, 100%y)
EditList.Initialize
PanelNb = DBFields.Size + 2
'Cycle through the fields that are given and create a panel for each one on the scroll View
For i=0 To DBFields.Size
Dim PanelForScroll As Panel
Dim lblField As Label
Dim edtField As EditText
PanelForScroll.Initialize("PanelForScroll")
ScrollViewMain.Panel.AddView(PanelForScroll,0,5dip+i*PanelHeight,100%x,PanelHeight)
lblField.Initialize("lblField")
'The first entry in the list is for the title, so do not treat it the same
If i = 0 Then
PanelForScroll.AddView(lblField,2%x, 5dip, 95%x, 40dip)
lblField.TextSize=30
lblField.Left = 35%x
lblField.Text= DBFields.Get(i)
Else If i = DBFields.Size Then
'Add buttons at the bottom
'Dim btnScrollSave As Button
btnScrollSave.Initialize("btnScrollSave")
PanelForScroll.AddView(btnScrollSave,2%x, 10dip, 95%x, 40dip)
btnScrollSave.TextSize = 20
btnScrollSave.Text = "Save"
btnScrollSave.Left = 0%x
btnScrollSave.Width = 45%x
Else
PanelForScroll.AddView(lblField,2%x, 5dip, 45%x, 40dip)
lblField.TextSize=20
lblField.Text= DBFields.Get(i)
End If
edtField.Initialize("edtfield")
'Again, the first field should be excluded for an edtField
If Not (i = 0) Then
If i = DBFields.Size Then
'Deal with buttons
Dim btnScrollCancel As Button
btnScrollCancel.Initialize("btnScrollCancel")
PanelForScroll.AddView(btnScrollCancel,50%x, 10dip, 45%x, 40dip)
btnScrollCancel.TextSize = 20
btnScrollCancel.Text = "Cancel"
btnScrollCancel.Left = 50%x
btnScrollCancel.Width = 45%x
Else
PanelForScroll.AddView(edtField,50%x, 5dip, 45%x, 40dip)
EditList.Add(edtField)
End If
End If
Next
'Actually add the view now
ScrollViewMain.Panel.Height=PanelNb*PanelHeight
End Sub
Sub btnScrollSave_Click
Debugger("Entering btnScrollSave_Click")
'Save all of the data
Dim foo As String
'PROBLEM HERE I see the text, but it is buried under
'edtlist > Array > 1 > mText > mText > and then 0 contains the first character, 1 for the next etc
foo = EditList.Get(1)
End Sub
How do I get "foo" to be the input from the edit text field? Is my approach to this incorrect?
Thanks,
Patrick