iOS Question How do I create a control array to hold a list of textboxes or pickers

davepamn

Active Member
Licensed User
Longtime User
I need a way to store a list of dynamically created textboxes or data pickers.


B4X:
Dim arrPicker(100) As Picker
Dim iPickerCounter As Int

iPickerCounter=0

arrPicker(iPickerCounter).Initialize("lbx" & iPickerCounter)
arrPicker(iPickerCounter).Tag=sTestId


Dim myList As List
myList.Initialize

oKeyValue.Initialize(sListText,oFont, Colors.Black)
oKeyValue.Tag=sListValue
myList.Add(oKeyValue)

arrPicker(iPickerCounter).SetItems(0,myList)
arrPicker(iPickerCounter).SelectRow(0,FindByValueWithAttributeString(arrPicker(iPickerCounter),0,sSelectedValue),True)


'Added the new control to the control array
If iPickerCounter<5 Then
   arrPicker(iPickerCounter)=oLBX
   iPickerCounter=iPickerCounter + 1
End If

ScrollViewInput.Panel.AddView(arrPicker(iPickerCounter),300dip,iRowOffset-(arrPicker(iPickerCounter).Height/2),50%x,500dip)

iRowOffset=iRowOffset+(arrPicker(iPickerCounter).Height)+100

If iPickerCounter<100 Then
     listControls.InsertAt(iPickerCounter,arrPicker(iPickerCounter))
     iPickerCounter=iPickerCounter + 1
End If

Sub cmdSave_Click
 
Dim i As Int

    For i =0 To listControls.Size-1
            Dim attr As AttributedString =arrPicker(i).GetItems(0).Get(i)
            Msgbox(arrPicker(i).Tag & "=" & attr.tag,"save_click")
    Next
end Sub

cmdSave_click is crashing.
Do I need to initialize my array of textfields and pickers if the controls I am storing are initialized?
 
Last edited:

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi
You can use array of view
Dim arr() as view
arr = array as view(picker1,textfield1,stepper)

and use it

dim p1 as picker
p1 = arr(0)
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
The number of controls are not known until I parse a XML string

I will need a collection of views to parse to return values back to the server

1. Dynamically create the text box or picker
2. Capture the values for each of the controls when a save button is pressed
3. Generate an httpjob post back to the server
 
Last edited:
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
I have a working solution! Yeah
B4X:
For i =0 To listControls.Size-1

        Dim iIndex As Int

        iIndex=arrPicker(i).GetSelectedRow(0)

        If iIndex>=0 Then

            Dim attr As AttributedString =arrPicker(i).GetItems(0).Get(iIndex)

            Msgbox("testid=" & arrPicker(i).Tag & "=" & attr.tag,"save_click")

        EndIf
 
Upvote 0
Top