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.
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 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
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
'
L.Text = ComboTxt.Text
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 y = 0 To 9
Dim L As Label
L.Initialize("Label")
q = Activity.NumberOfViews : Lvno.Text= q
Activity.RemoveViewAt(6)
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
Last edited: