Share My Creation Dynamic List multi text

Hello to all,
I wrote, a few days ago, in my last message about ComboBox Emulation, that there was also a new experiment I was doing, always in relation to list boxes, (not necessarily intended as Combo Box) to create and use through code rather than to manage as a view of the designer.

It 'true that such an approach does not always bring benefits over view provided by the system and/or enhanced.
But I still think that when the required functions are limited to the response to a click event (common case in my program Remme, target of the simplification of the code) this could be a solution.
So you will find here a list of various elements (labels) dynamically created and deleted when no longer needed.
(I did the same thing with Edit Text views and it works but it is more difficult to manage the size of elements and text)

The example proposed (and therefore the relevant code) behaves in analogy to what happens in my program Remme using the arrow.
For those who do not know it, the code allows you to create a list, fill it with sensitive elements to the event "Click".
If the event is applied to the list the same will be filled with details of the chosen element and using again the arrow this list is deleted (with the difference that is not made invisible but do not exist anymore its components.

As I had already written the code is inspired by the example TiC, TAC, TOE Availlable in the tutorial B4A where dynamic creation of the objects (Buttons in that case) is used to create the elements of the game.
The code follows. Have fun.

CODE Start

Sub Process_Globals

End Sub

Sub Globals
Dim Albl1 As Label
Dim Button1 As Button
Dim List2 As Label
Dim Dida(11)
'Dim Labels(11,11) No longer required
Dim CTx As Label
Dim Lvno As Label
Dim Img1 As ImageView

Dim Nlist As String
Dim Tx As Int
Dim Lvy As Boolean
Dim Lista As String
Dim KA As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("RMnew1")

Dida(0) = "Cards,Documents,Phones,Bank,Web Site,ProgKeys,Insurance,Medical,Cars-Bikes,Archive1,"
Dida(1) = "Card,Bank,Number,Name,Validity,Phone,Pin,Note,Note1,Image,"
Dida(2) = "Doc.Name,Number,Holder,Issued on,Issued By,Validity,Renewal,Note,-,-,"
Dida(3) = "Number,Ph. or Cell,Provider,PIN,PUK,SIM,Validity,User,Ph.Model,Support,"
Dida(4) = "No.Count,Count Type,Currency,Bank,Agency,Holder,Issued on,Credit rate,Debit rate,Contact,"
Dida(5) = "Site Name,Topic,Url,ID o Mail,PassKey,Support,Note,-,-,-,"
Dida(6) = "Program,Version,Developer,Support,Url,Mail,Serial,PassKey,Purchased on,Upgraded,"
Dida(7) = "Policy No.,Insurance Co,Risk Cover,Issued on,Validity,Premium,Holder,Beneficiary,Contact,-,"
Dida(8) = "Medicine,Dosage,To cure,Validity,Doctor,Medical Test,Last Date,-,-,-,"
Dida(9) = "Manufacturer,Model,Plate,Car Tax,Validity,Assistance,Check,Tyres,Dimensions,-,"
Dida(10) = "Field1,Field2,Field3,Field4,Field5,Field6,Field7,Field8,Field9,Field10,"
Lvy = False
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
Activity.Finish
End Sub

Sub Crealist
'For x = 0 To 9
Lista = Dida(KA)
For y = 0 To 9
Dim L As Label
L.Initialize("Label")
L.Color = Colors.White
L.TextSize = 12
If KA = 0 Then L.TextColor = Colors.Red
If KA <> 0 Then L.TextColor = Colors.Blue
Activity.AddView(L,0,List2.Top + y * (CTx.Height + 1dip),Albl1.Width,CTx.Height)
'Activity.AddView(L,0,150 + y * (21 + 1dip),100,21)
L.Gravity = Gravity.CENTER_VERTICAL
Tx = (Lista).IndexOf(",")
CTx.Text = Lista.SubString2(0, Tx)
Nlist = Lista.SubString2(Tx+1, Lista.Length)
Lista = Nlist
'Labels(x, y) = L
L.Text = ComboTxt.Text
Next
'Next
Lvy = True
Lvno.Text = Lvno.Text & Activity.NumberOfViews
End Sub

Sub Label_Click
'Using Sender we find the label that raised this event
Dim L As Label
L = Sender
If Albl1.Text = "ARCHIVES" Then
Albl1.Text = L.Text
If Albl1.Text = "Cards" Then KA = 1
If Albl1.Text = "DocumentS" Then KA = 2
If Albl1.Text = "Phones" Then KA = 3
If Albl1.Text = "Bank" Then KA = 4
If Albl1.Text = "Web Site" Then KA = 5
If Albl1.Text = "ProgKeys" Then KA = 6
If Albl1.Text = "Insurance" Then KA = 7
If Albl1.Text = "Medical" Then KA = 8
If Albl1.Text = "Cars-Bikes" Then KA = 9
If Albl1.Text = "Archive1" Then KA = 10
ClearList
List2.Visible = True
Crealist
End If
End Sub

Sub ClearList
Dim q
'For x = 0 To 9
For y = 0 To 9
Dim L As Label
L.Initialize("Label")
q = Activity.NumberOfViews : Lvno.Text= q
Activity.RemoveViewAt(6)
Next
Next
Lvy = False
End Sub

Sub Img1_Click
ArrowGes
End Sub

Sub Albl1_Click
ArrowGes
End Sub

Sub ArrowGes
If Albl1.Text = "ARCHIVES" Then
If Lvy = False Then
KA = 0
Crealist
Else
ClearList
End If
Else
If Lvy = True Then
ClearList
List2.Visible = False
Albl1.Text = "ARCHIVES"
End If
End If
End Sub

\CODE End

ATTN.
To delete the list you need to use the Index of view, relating to the dynamic list of labels, in the Activity used.
So to add or to delete views from the parent activity, by the designer also, may cause errors or no deletion of the list.
 

Attachments

  • DynammicList0.png
    DynammicList0.png
    28.4 KB · Views: 3,469
  • DynamicList1.png
    DynamicList1.png
    33.1 KB · Views: 388
  • DynamicList2.png
    DynamicList2.png
    36 KB · Views: 419
  • RemMeNewGen2.zip
    325.8 KB · Views: 259
Last edited:

NJDude

Expert
Licensed User
Longtime User
When posting code, please enclose it between the [code] ... [/code] tags, but would be even better if you attached your project, in this case you are using a layout, the source code alone is not much of a help.

Using the IDE click on FILE -> Export as ZIP
 
Last edited:

efsoft

Member
Licensed User
Longtime User
When posting code, please enclose it between the [code] ... [/code] tags, but would be even better if you attached your project, in this case you are using a layout, the source code alone is not much of a help.

Using the IDE click on FILE -> Export as ZIP

Thanks for the reply and of course you're right.
In added in my other post, depending on the time and the context, or the apk file and lately the zip file with all the necessary elements ..
In this case, the code represents the first attempt and, even as it runs, is quite far from it can be considered complete.
(problems that have been recognized: it does not seem to want to install under Jelly Beam and moved on tablets needs to control the position in which the labels appear in the list)
This stopped me from inserting the file implementation of the code for the moment.
Just solved the various problems in a satisfactory manner i will add the file with the required elements (or will I require your help otherwise)
Thank you for your attention and ....... sorry for my English.
 

efsoft

Member
Licensed User
Longtime User
Hello to all
in order to meet the demand to make the program available in an operational form I tried to quickly solve some of the problems that I found and to create a test program that shows what I mean by "Dynamic list multi text"
I managed to solve the failure load under Jelly Beam (just a local problem), but appeared unresolved to adapt the layout to different sizes.

I think that being the objects dynamically created out of the designer the autoscale instructions may not apply to objects created directly through code.
Waiting to explore this aspect, to allow a passable use of the test program I applied a shortcut that leaves unresolved only changing the size of the text. I corrected the line of the code previously published using red to indicate the corrected line.
In practice i used the dimensions of other objects of which the designer change the size to adapt the dimensions of the labels created dynamically.
Even if it works this is not the correct solution , but only a trace of how many things I have yet to learn about the Basic Android (B4A).
The modified code is now attached here and directly usable in Zip format.

Criticisms and suggestions are always welcome. Predict long time to get a code really correctly and functional.

User Notes: To test how the dynamic list works, launch the program, tap the arrow to display the list populated of names of Archives, Select and tap one of the archive of the list. The chosen name will appear in the window on the side of the arrow while the list will show all the elements of the selected archive changing the text color from red to blue. On the side you will see a field used in the final program to show the values relating to the items shown in the list.
Press again the arrow to close the list and start a new search to select a different archive of the list with the text in red.
 

Attachments

  • RemMeNewGen2.zip
    325.8 KB · Views: 228

efsoft

Member
Licensed User
Longtime User
Clarification.

Hello to all,
the zip file posted by the previous message is what is necessary to show how to apply the dynamic creation of objects in this case to a list.
You found here, the code to create it, use it (click event) and clear it (i.e. delete ).
This last function, as already indicated, uses the instruction "Activity.RemoveViewAt" that to do the work needs the address of the created list .
If, as in the trial file, the list is the last object created the problem is easy to solve, but if you want to use this code to develope a program
happens that every time you add or delete a view by designer, the cancellation of the list occurs incompletely or not happen at all.
A consequence of the change in the index of objects in the Layout.
To avoid this and to automatically adjust the index try replacing the instruction:
Activity.RemoveViewAt (7) 'fixed value
with
Activity.RemoveViewAt (Lvno.text-1)
to pass to the instrution the value read from the label Lvno that precisely monitors the index that interests us.
For the moment it seems to work for me while I'm changing the code of my program Remme adding and removing elements of the layout depending on what is necessary.
 

efsoft

Member
Licensed User
Longtime User
Latest news

I just finished to apply the code of the dynamic list to my program RemMe where it seems to work properly.
In my case, a single list of 10 elements ( Labels ) is used to replace two list view .

This was already foreseen in the example posted here but complicates the code inside the program because it is necessary not to interrupt the sequence of index creation and deletion of dynamic labels .
What I mean is that if the program incorrectly requires the deletion of the list and the same is not open, the operation hangs and so on...

In addition using this kind of list you miss the information if the list is visible or not. So you have to create a variable boolean that change in true or false when you call CreateList or ClearLis Subs to check these events.

Another problem is the use of a program with dynamic list on the display of different sizes.
Being dynamic objects (i.e. created on demand ) it is difficult to subject them to autoscale instructions .
It may be that I am wrong , however , to get around the obstacle I have created a label with the same characteristics as those that will be created as a dynamic list .
While the label-guide is invisible, its dimensions and other values (textsize) are assigned to the values of the code that creates the list.
If assume that Label-Guide is CTx label then

Example:

For y = 0 To 9
Dim L As Label
L.Initialize("Label")
L.Color = Colors.White
L.TextSize = CTx.textsize
.........
Activity.AddView(L,0dip,List2.Top + y * (CTx.Height + 1dip),Albl1.Width,CTx.Height)
......... etc
End Example

I used also, to fix the position of the dynamic elements, some properties of others objects around.(i.e List2 or Albl1)

May be that this is not an elegant development solution but... i am sorry. I started to use something like Basic on a ZX81 and as a self-taught Italian i am a representative of the, so called, many time ago, "Spaghetti Code", if there is here someone that remember that times

In this way, when the program (320x480x160) will be installed on others devices the Label-Guide shall be affected by Autoscale instructions and labels created will be of the correct dimension

Well i think that this is all for the moment.
For those who want to see the finished result the BETA Version (RemMe2014.zip) that uses dynamic lists has been added to the post of the program Remme here in the forum.
 
Last edited:

efsoft

Member
Licensed User
Longtime User
Ooops!
It happens, when you try to learn through the examples of code, to use the code found without checking if it contains unnecessary parts for the use that we make of it.
This happened to me using part of the program code Tic.Tac.Toe to learn how to create objects dynamically (without using the "Designer").
So, having found the code, I did not notice for a long time that what I was using in my programs did not need a double-For-Next loop.
In fact, the double loop was used in the example program to create the gaming keyboard while I was using only a vertical alignment of labels.
This does not create problems to my programs but the text of the published code requires the correction indicated. (See theCancelled lines)
Sorry for the oversight.
Code will be adjusted at the earliest opportunity (now in this case) while i will correct the programs on the update of the same.
 
Top