We go to practice
Hello to all,
As I wrote, I'm using the experimental ComboBox instead of Android ListView to create pop-up menus for an update of my program RemMe.
In doing this I had necessarily to revise the code previously posted since the use as a menu is definitely simpler than the ComboBox and has different needs.
The first thing: there is no need of the button of combobox that normally opens and closes the list box to store in it the elements passed as input.
All the items you need will be loaded by the program at start up and the entries are already defined and, if they are for a menu of 4 elements. is useless manage 10 items as in the original example .
As menu does not need also to input nothing, this allows you to change the structure of the ComboBox using 2 labels only, instead of EditBox, Label and ImageView. The only element indispensabie is the Panel which must be calibrated to better select, in small screens, the distance of the items to be selected at the touch.
So the final code (almost) to apply to RemMe, but to any other menu also, becomes the following:
(I tried to add us notes for each piece of code.)
Sub Globals
Dim Li(4)
Dim Panel1 As Panel
Dim L1 As Label
Dim Id, D, n As Int
Dim KY As Float
Dim Lista, Lr, La, Nlist As String
Dim Tx As Int
........
End Sub
Sub Activity_Create(FirstTime As Boolean)
..........
n = 0
D = L1.Height '(i.e 16)
End Sub
Sub Lf1_Click 'Coordinate/index converter.
Select Case True You can see that the items reduced to 4 only)
Case KY < (D*2) : n = 1 : Lfun.Text = Li(n)
Case KY < (D*3) : n = 2 : Lfun.Text = Li(n)
Case KY < (D*4) : n = 3 : Lfun.Text = Li(n)
Case KY < (D*5) : n = 4 : Lfun.Text = Li(n)
End Select
L1.Visible = False : L9.Visible = False 'L9 is the frame of the label L1 (the list)
Panel1.Enabled = False
Lmen 'this is a sub to check if action selected can executed correctly
End Sub
Sub GesMen 'Combo Behaviour Module base
The RED code is the one deleted
being useless for the menu use
'If Lfun.Text = "" AND L1.Text = "" Then
'Return
'Else
'If Lfun.Text = "" AND L1.Text <> "" AND L1.visible = False Then
'L1.visible = True : L9.Visible = True
'Panel1.Enabled = True
'Else
'L1.Visible = False : L9.Visible = False
'Panel1.Enabled = False
'End If
'End If
'If Lfun.Text <> "" Then
'For w = 1 To n
'If Lfun.Text = Li(w) Then Lfun.Text = ""
'Next
'End If
This is instead the code to load
a single item into a line of the list
If Lfun.Text <> "" AND t < 4 Then
L1.Text = L1.Text & CRLF & Lfun.Text : n = n + 1
Li(n) = Lfun.Text
L1.Height = L1.Height + D : Panel1.Height = L1.Height
L1.Visible = True : L9.Visible = True 'L9 is only the frame of the L1 Label (the list)
Lfun.Text = ""
Panel1.Enabled = True
Panel1.RequestFocus
End If
End Sub
Sub Panel1_Touch (Action As Int, O As Float, V As Float) As Boolean
If Action = Activity.ACTION_DOWN Then
KY = Round(V)
End If
L1_Click The value will be used by the Sub L1 to obtain the index of the item.
End Sub
A peculiarity of the menu Remme (already available in previous versions) is to use a single list retractable driven by two different keys alternately.
This therefore requires that the exchange program to request the list of items displayed to the user.
This is the task the following code that differrisce from that used for the ComboBox itself.
Not being used the combobox button will be the keys that call to pass the instruction to make visible or invisible after updating the list in accordance with the given key.
Sub LFunList 'Rapid Add items module
L1.Text = ""
L1.Height = D
Panel1.Height = L1.Height
Panel1.Enabled = True
n= 0 : Dim Li(4)
If Archem.Enabled = False Then Lista = "Nuovo Record,Modif.Record,Canc Record,"
If Recorm.Enabled = False Then Lista = "Rinomina Arch.,Titoli Campi,Cambia Settaggi,"
Do Until Lista.length = 0
Tx = (Lista).IndexOf(",")
Lfun.Text = Lista.SubString2(0, Tx)
GesMen
Nlist = Lista.SubString2(Tx+1, Lista.Length) '(resto stringa da Sinistra)
Lista = Nlist
Loop
End Sub
Code has been tested under GB 2.3.3, ICS 4.0.4 and now also under JelyBeam 4.2 and appears to work correctly
Tanks for attention.