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.
PART 2 : Adapting & Deleting Dynamic elements
(I.e., create and delete views using code)
1) In part 1 of these notes was dealt with how to create dynamic views in B4A.
There is also a different aspect of the creation of dynamic views that regards the adaptation to different types and sizes of the screen
The reference procedure is the 'AutoScaleAll script to fit the layout, but dynamic objects, arise directly from the code.
For this reason, their dimensions are present only in the line code Activity.AddView (.........) as we have seen.
Abandon the use of AutoScale would not be convenient and for this reason the Layout abandoned for the use of dynamic objects is called up into service.
It 'simply create, using the Designer, a main.bal that contains only one element. A Label.
The size of the label used (we'll call LG i.e. Label Guide) must be chosen so as to create for multiple and/or parts of them all required measures.
This will make it possible to activate the script AutoScaleAll applying it to dynamic views.
An example:
The LG Label this program, made entirely through code, the size of 8x100 (Heigth x Width)
Thus the height of a menu is (LG.Heigth * 2) -
The width of the menu is equal to LG.Width -
while the width of the WebView that displays the selected data appears to be LG.Width * 3.
Also do not forget that even LG.TextSize can be used as a parameter.
At this point, with a simple single object in Layout, we are able to resize all dynamic objects used in a program
It is obvious that, if your program already has a layout with a variety of views necessary measures can be invoked by the objects existing in it without needing Label Guide.
There remains one last problem to solve.
Although the layout is used to provide the script AutoScaleAll compatible measures is impossible to use the UI.Cloud Designer to see how our program can be adapted to different screens.
To solve it you just have to create a Layout "fakemain" where the designers are part of the same views in the project that we have created through code.
Without this, just save it and send it to the UI Cloud to graphically see how the adjustments to the parameters applied AutoScaleAll.
Obviously you will never use, in reality, the layout "fakemain" which will remain a version control that otherwise would cause the program to lock.
But to use the dynamic views is necessary not only to create them and make them adaptable but also, and above all to be able to delete them in the correct manner.
We can say that it is more difficult to delete a dynamic object than create it.
Consider that, whatever the system with which you add the view to a Activity these are identified by an index.
A member of the Activity NumberOfView (Read only) gives the number of the views contained in what is generalmante the main Parent.
When using the designer numbering index remains unchanged, as or understood, only if you use the instructions BringInFront or SendToBack.
But in this case the order is altered but not the total index (ie the number of view). Then the index is incremented after each addition of a view and, once you have created your layout optimal, index remains unchanged
The problem does not arise if, after you create a view with the code, the same will remain in effect forever, until closing the program or if the dynamic view is created and, after use, immediately cleared.
The thing is a bit 'different when using dynamic views along with a layout created with the designer and they are created and deleted as needed.
In this case the number of view present in an Activity becomes a variable to be evaluated equally dynamically.
In this light fits the suggestion to add dynamic objects only after those created by the designer.
In fact, the only statement applicable to delete dynamic objects is widely RemoveViewAt (index)
So adding at the end the dynamic objects you will have to check only the final value of the index to delete the added dynamic views as the fixed views remain unchanged.
To do this, I used this code:
qq = Activity.NumberOfViews: BV = qq
This line of code reads the Quantity (qq) of view in the Activity and the value it assigns to the variable BV.
If placed at the beginning of the routine in our program before creating dynamic view, this code will provide us with the value of BV (Basic View), which represents the number of standard view (not dynamic) already present.
When this is done when the program starts the same line of code, placed at the end of the routine of creating a dynamic object will give us the current value of the index will be assigned to a different variable as you can see. qq = Activity.NumberOfViews: LN = qq-1
Once you have obtained these values can be passed to the Sub cancellation as follows:
Sub ClearList
qq = Activity.NumberOfViews: LN = qq-1
For m = LN To Step -1 BV
Activity.RemoveViewAt (m)
Next
end Sub
You can see that the line of code that detects the number of active views is inserted at the beginning of the cancellation Sub.
This ensures that the measured value is as current as possible before you start erasing.
This Sub is born for the cancellation of lists of dynamic views but can also operate to erase a single object.
However, when you create a single object it is possible to not use the above proceduresand use the instriction RemoveView.
It may be the case of an ImageView dynamically create and removed immediately after seeing of the picture.
I apologize for 2 things.
The first is my poor english.
The second: to want to teach to you something .
In fact i am a beginner, if not for the basic, certainly for Android and B4A and therefore are not able to teach a lot,
I just compiled these notes to determine the experments done that surelyl work, since you are using this program built according to the principles explained.
Have fun.