The Views(Core) page is available on line here : http://www.basic4ppc.com/android/help/views.html
Rem B4a was born to use multiple dynamic menu as evolution of SlimLine Menu project 2014.
For this i add here some information to help the user to create dynamic views (single or multiple) as the user may need.
NOTE: Creating Dynamic elements
(I.e., create and delete views using code)
1) To use dynamic views in B4A you must first define the type of item and then initialize the View for the selected type. (Initialization is not required if you use the B4A Designer)
Suppose to create a Label called DynLab and write:
Dim DynLab as Label
DynLab Initialize("Label")
Once this is done, using the following line of code, you create a graphical representation of the element
Activity.AddView(DynLab, Left, Top, Width, Heigth)
The desired object is created, without triggering any file layout, as its source is the code.
To complete the item as you would, you need to add the members to what is, for the moment, only part of the Activity (which is the Parent)
You must define the members applicable to the dynamic view (you have them also listed here for each view in this program).
To do this you just need to write a line of code, which is equivalent to selecting an entry or assign a value into the Designer.
Here are a few examples.
DynLab.TextSize = 14
DynLab.TextColor = Colors.Blue
DynLab.Color = Colors.White
DynLab,Visible = True
.....and so on.
Remember that the Characteristics of the Text use different syntaxes like Gravity and TypeFace, see the following example:
DynLab.Typeface = Typeface.DEFAULT_BOLD
DynLab.Gravity = Gravity.CENTER_VERTICAL
DynLab.Gravity = Gravity.CENTER_HORIZONTAL
For the Events, the dynamic view offers the ones of the core view to which you refer in the Dim declaration.
2) The previous paragraph shows how to create a single dynamic view of any type (Button, Label, Panel, EditText etc)
However, the maximum value found using the multiple views organized as lists (horizontal or vertical)
In fact, using a simple For / Next loop connected to the change of the variable Left or Top you can get an array whose elements are the dynamic created view.
The code probably says it best:
For x = 1 To 3
Dim DynLab As Label
DynLab.Initialize("Label")
DynLab.Visible = True
DynLab.Color = Colors.White
DynLab.TextColor = Colors.Black
.........
DynLab.Tag = x
Activity.AddView(DynLab, (Left + (x-1) * Width+1), Top, Width, Height) 'Horizontal Alignment
-or-
Activity.AddView(DynLab, Left, (Top + (x-1) * (Height+1), Width, Height) 'Vertical Alignment
Next
A list like this is not indexed (despite being created through a progressive index)
So to turn on or read an item is used the following system:
It uses the Click event of the view reference (Label)
After havung initialized the dynamic view, with Senders, the label Click on the desired dynamics view.is reported to the code contained in the sub
Here is the code:
Sub Label_Click
Dim DynLab As Label
DynLab.Initialize("Label")
DynLab = Sender
k = DynLab.Tag
LL = DynLab.Left
End Sub
The code also provides a system for indexing indirectly the elements of the dynamic list.
It is the use of the member Tag.
The code used to create the DynLab you will notice that the For / Next loop attaches to tag each label the value of its index.
So when you press one of the Sender label there is the index of the item but you can still detect it by reading the tags
In the example sub the last instruction reads the position Left of the label (Sender) clicked
3) So far we have created a dynamic single label and a list of labels.
This methods are generally combined with a layout that contains other elements of a program to add some dynamic items ..
But we can also create multiple dynamic objects (even of the same type but with different uses) and use them to make a program without Layout.
We still use the Labels to show text, to use as buttons and to form a list of labels.
The reference object is the same for all 3 types ("Label") but use them separately is a need
I got it declaring different names but they all refer to the Label view.
To clarify, I used a code as follows:
Global
Dim DynLab as Label
Dim LabelA as Label
Dim LabelB as Label
e così via per ogni altro elemento label presente.
Quanto sopra permette di diversificare gli eventi Click utilizzando:
Sub Label_Click
DynLab.initialize("Label")
DynLab = Sender
.....................
End Sub
Sub LabelA_Click
DynLabA.initialize("LabelA")
DynLabA = Sender
...................
End Sub
Sub LabelB_Click
DynLabB.Initialize("LabelB")
DynLabB = Sender
...................
End Sub
For the "creation" remains only to remember the code used to populate the lists of label that allows you to do so simultaneously with the creation of the list.
The system uses a string where the contents of the labels is shown separating each element with a comma.
Here is an example : Lista = "First,Second,Third,.......,Last," of the string that the following code uses to populate the label of a list.
Tx = (Lista).IndexOf(",")
DynLab.Text = Lista.SubString2(0, Tx)
Nlist = Lista.SubString2(Tx+1, Lista.Length) '(remaining Lista string)
Lista = Nlist
Next
Remember that the above code must be used only if you create a Dynamic List of view that need to contain text for each item.
In this case the code must be inserted into the Loop For/Next, after the views creation code, at the end of the Loop