For a VB6 project of mine, I used a universal form to show and edit a set of entries (of a database or just some settings).
Translating this to B4A, I created a little helper which might be useful to other users. It is not perfect, but I started with B4A two weeks ago...
Call it just as
It will return ret=-1 if the OK button was pressed, and the Values list updated with the new entries, otherwise is ret=-2 and Values remain unchanged.
Labelwidth (from 10 to 90, like %) is used to balance the label width with the EditText. 50 means equal width for both.
I use CustomDialog (from DIALOG library) to create a panel with a number of labels and EditTexts according to the size of the Label list.
This dialog is "modal" (as much as it can be - it will be destroyed by rotating the device). No global variables or views or event handling SUBs are necessary - just continue inside the SUB which calls MuEdit.
This is the code. I appreciate every improvement, especially of naming the buttons automatically according to the language used.
Translating this to B4A, I created a little helper which might be useful to other users. It is not perfect, but I started with B4A two weeks ago...
Call it just as
B4X:
ret = MuEdit(Title As String, Labels As List, Values As List, Hints As List, Labelwidth As Int)
Labelwidth (from 10 to 90, like %) is used to balance the label width with the EditText. 50 means equal width for both.
I use CustomDialog (from DIALOG library) to create a panel with a number of labels and EditTexts according to the size of the Label list.
This dialog is "modal" (as much as it can be - it will be destroyed by rotating the device). No global variables or views or event handling SUBs are necessary - just continue inside the SUB which calls MuEdit.
This is the code. I appreciate every improvement, especially of naming the buttons automatically according to the language used.
B4X:
Sub MuEdit(Title As String, Labels As List, Values As List, Hints As List, Labelwidth As Int) As Int
' Multiple line input dialog. Uses Lib 'Dialogs' by Andrew Graham
' Dimension of Lists has to be equal or at least that of 'Labels'
' This SUB is modal. No global variables or additional SUBs are necessary. It will return
' the original ret value of CustomDialog. Values are changed only if "yes"/"OK" button is pressed.
' Please adapt the Button Texts of CustomDialog as you need them
' Use Labelwidth to vary the relation between prompts/labels and EditTexts. 10-90. 50 means equal.
Dim cd As CustomDialog
Dim scv As ScrollView
Dim NumberofItems,i As Int
Dim lwidth,ewidth As Int
NumberOfItems = Labels.Size
If Labelwidth<10 Then Labelwidth = 10
If Labelwidth>90 Then Labelwidth = 90
scv.Initialize((NumberofItems+2)*50dip)
lwidth = (90%x*Labelwidth/100-6)*1dip
ewidth = (90%x*(1-Labelwidth/100)-10)*1dip
scv.Color = Colors.DarkGray
Dim InLabel(NumberOfItems) As Label
For i=0 To NumberOfItems-1
Inlabel(i).Initialize(""): Inlabel(i).TextSize = 14
InLabel(i).Gravity=Gravity.CENTER_VERTICAL
Inlabel(i).Text = Labels.Get(i)
scv.Panel.AddView(InLabel(i),5dip,i*50dip,lwidth,46dip)
Next
Dim MuEditInputs(NumberOfItems) As EditText
For i=0 To NumberOfItems-1
MuEditInputs(i).Initialize("")
MuEditInputs(i).Text = Values.Get(i)
MuEditInputs(i).Hint = Hints.Get(i): MuEditInputs(i).HintColor = Colors.LightGray
scv.Panel.AddView(MuEditInputs(i),lwidth+10dip,i*50dip+2dip,ewidth,50dip)
Next
i=i*50dip: If i > 90%y Then i=90%y
cd.AddView(scv, 0,0,90%x,i) ' sizing relative to the screen size is probably best
'adapt your button texts as needed here. I do not use the "no" button.
ret = cd.Show(Title, "OK", "", "Cancel", Null)
If ret = -1 Then '
For i=0 To MuEditInputs.Length-1
Values.Set(i, MuEditInputs(i).Text)
Next
End If
Return ret
End Sub