Hello to all.
This time is an experiment rather than a program that i present you
If RemMe (that you can find here in other 3D) was my first program under Android it was also the translation of one Basic program under Windows.
One of the objects of the Windows version that i had to replace in the Android/B4A layout is the ComboBox.
I know that B4a uses Spinner that remembers a ComboBox but i dont like it much, even if it is surely much more powerful and integrated of my experimental combo.
So i am trying to create my combobox using the code (as simple as possible to use it in other programs if necessary).
Basically the problem is to create items indexed using something that do not has this property.
The behaviors required to Android ComboBox are as follows:
- Writing of text elements in Inputbox and loading the text on the list by pushing the button on the side.
- List of 10 elements (maximum for current experiment)
- Selection of a list element with simple touch with transfer of selection in the inputbox
- Clear of the InputBox with the use of the arrow key and call of the entire list with a subsequent use of the same key.
To achieve this, I used a EditBox, an ImageView and a Label placed as seen from the attached image to form a ComboBox (actually the label is initially empty and invisible.
Since they are 3 customizable standard views by the designer, combo box can be customized (background,color etc) as user likes
First, the EditBox enables the keyboard and once wrote the text in it using 'ImageView as a button (Click event) the transfer is made of what is written in the list (label) that appears below the EditBox.
Continuing to write new texts in inputbox the label extends automatically to accommodate the new elements of the list.
It should be noted that, at the same time an item is added to the list, the same text is also added to an array of strings (associating them so an index).
Now it comes the worse. Select in the Label/List a single element is not difficult but it becomes so if we want to pull it out with a single touch.
To do this I add a panel (kept transparent) and I use his property to return the coordinates of the touch position. (just the Y)
One thing that I did not say is that the label (list) each time you add an item stretches a strip of fixed dimensone (16 for label height, 12-point font Bold) and the Panel does exactly the same thing.
This means that if the Y coordinate falls into a precise interval 0-16/17-32/33-48 etc you can assign it an index using the Select Case statement.
Obtained the index (float value is converted into Int) just call the element, with the index found, from the array and insert it as the text of the EditBox and you're done.
This below is the code:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ComboTxt As EditText
Dim Img1 As ImageView
Dim L1 As Label
Dim Li(11)
Dim n, D, t As Int
Dim Panel1 As Panel
Dim KY As Float
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("Combo0")
n = 0
D = L1.Height
End Sub
Sub L1_Click 'Extracts the index by the coordinates of the touch screen
Select Case True
Case KY < (D*2) : t = 1 : ComboTxt.Text = Li(t)
Case KY < (D*3) : t = 2 : ComboTxt.Text = Li(t)
Case KY < (D*4) : t = 3 : ComboTxt.Text = Li(t)
Case KY < (D*5) : t = 4 : ComboTxt.Text = Li(t)
Case KY < (D*6) : t = 5 : ComboTxt.Text = Li(t)
Case KY < (D*7) : t = 6 : ComboTxt.Text = Li(t)
Case KY < (D*8) : t = 7 : ComboTxt.Text = Li(t)
Case KY < (D*9) : t = 8 : ComboTxt.Text = Li(t)
Case KY < (D*10) : t = 9 : ComboTxt.Text = Li(t)
Case KY < (D*11) : t = 10 : ComboTxt.Text = Li(t)
End Select
L1.Visible = False
End Sub
Sub Img1_Click 'It handles the behavior of CombBox
If ComboTxt.Text = "" AND L1.Text = "" Then
Return
Else
If ComboTxt.Text = "" AND L1.Text <> "" AND L1.visible = False Then
L1.visible = True
Else
L1.Visible = False
End If
End If
If ComboTxt.Text <> "" Then
For w = 1 To n
If ComboTxt.Text = Li(w) Then ComboTxt.Text = ""
Next
End If
If ComboTxt.Text <> "" AND n < 11 Then
n = n + 1
L1.Text = L1.Text & CRLF & ComboTxt.Text
Li(n) = ComboTxt.Text
L1.Height = L1.Height + D : Panel1.Height = L1.Height
L1.Visible = True
ComboTxt.Text = ""
Panel1.RequestFocus
End If
End Sub
Sub Panel1_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Read coordinate
If Action = Activity.ACTION_DOWN Then
KY = Round(Y)
End If
L1_Click
End Sub
As experiment I do not even classify as Beta. Obvious that the project need still to be optimized.
For the moment I still have to add the deletion of a single element and of the entire list while preloading of a whole list is under test .
If you use the ComboBox leaf as a simple menu of course you will have to enter in the code of the application or set the desired elements reading them from file at startup.
And i know also i have to increase distance of the items of the list to enable a better use by touch of the screen even if on my old GT P100 Samsung the selection works well.
The program works correctly on emulator 320x480 160dpi (base 1)
Have fun. (More detaill will follow)
This time is an experiment rather than a program that i present you
If RemMe (that you can find here in other 3D) was my first program under Android it was also the translation of one Basic program under Windows.
One of the objects of the Windows version that i had to replace in the Android/B4A layout is the ComboBox.
I know that B4a uses Spinner that remembers a ComboBox but i dont like it much, even if it is surely much more powerful and integrated of my experimental combo.
So i am trying to create my combobox using the code (as simple as possible to use it in other programs if necessary).
Basically the problem is to create items indexed using something that do not has this property.
The behaviors required to Android ComboBox are as follows:
- Writing of text elements in Inputbox and loading the text on the list by pushing the button on the side.
- List of 10 elements (maximum for current experiment)
- Selection of a list element with simple touch with transfer of selection in the inputbox
- Clear of the InputBox with the use of the arrow key and call of the entire list with a subsequent use of the same key.
To achieve this, I used a EditBox, an ImageView and a Label placed as seen from the attached image to form a ComboBox (actually the label is initially empty and invisible.
Since they are 3 customizable standard views by the designer, combo box can be customized (background,color etc) as user likes
First, the EditBox enables the keyboard and once wrote the text in it using 'ImageView as a button (Click event) the transfer is made of what is written in the list (label) that appears below the EditBox.
Continuing to write new texts in inputbox the label extends automatically to accommodate the new elements of the list.
It should be noted that, at the same time an item is added to the list, the same text is also added to an array of strings (associating them so an index).
Now it comes the worse. Select in the Label/List a single element is not difficult but it becomes so if we want to pull it out with a single touch.
To do this I add a panel (kept transparent) and I use his property to return the coordinates of the touch position. (just the Y)
One thing that I did not say is that the label (list) each time you add an item stretches a strip of fixed dimensone (16 for label height, 12-point font Bold) and the Panel does exactly the same thing.
This means that if the Y coordinate falls into a precise interval 0-16/17-32/33-48 etc you can assign it an index using the Select Case statement.
Obtained the index (float value is converted into Int) just call the element, with the index found, from the array and insert it as the text of the EditBox and you're done.
This below is the code:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ComboTxt As EditText
Dim Img1 As ImageView
Dim L1 As Label
Dim Li(11)
Dim n, D, t As Int
Dim Panel1 As Panel
Dim KY As Float
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("Combo0")
n = 0
D = L1.Height
End Sub
Sub L1_Click 'Extracts the index by the coordinates of the touch screen
Select Case True
Case KY < (D*2) : t = 1 : ComboTxt.Text = Li(t)
Case KY < (D*3) : t = 2 : ComboTxt.Text = Li(t)
Case KY < (D*4) : t = 3 : ComboTxt.Text = Li(t)
Case KY < (D*5) : t = 4 : ComboTxt.Text = Li(t)
Case KY < (D*6) : t = 5 : ComboTxt.Text = Li(t)
Case KY < (D*7) : t = 6 : ComboTxt.Text = Li(t)
Case KY < (D*8) : t = 7 : ComboTxt.Text = Li(t)
Case KY < (D*9) : t = 8 : ComboTxt.Text = Li(t)
Case KY < (D*10) : t = 9 : ComboTxt.Text = Li(t)
Case KY < (D*11) : t = 10 : ComboTxt.Text = Li(t)
End Select
L1.Visible = False
End Sub
Sub Img1_Click 'It handles the behavior of CombBox
If ComboTxt.Text = "" AND L1.Text = "" Then
Return
Else
If ComboTxt.Text = "" AND L1.Text <> "" AND L1.visible = False Then
L1.visible = True
Else
L1.Visible = False
End If
End If
If ComboTxt.Text <> "" Then
For w = 1 To n
If ComboTxt.Text = Li(w) Then ComboTxt.Text = ""
Next
End If
If ComboTxt.Text <> "" AND n < 11 Then
n = n + 1
L1.Text = L1.Text & CRLF & ComboTxt.Text
Li(n) = ComboTxt.Text
L1.Height = L1.Height + D : Panel1.Height = L1.Height
L1.Visible = True
ComboTxt.Text = ""
Panel1.RequestFocus
End If
End Sub
Sub Panel1_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Read coordinate
If Action = Activity.ACTION_DOWN Then
KY = Round(Y)
End If
L1_Click
End Sub
As experiment I do not even classify as Beta. Obvious that the project need still to be optimized.
For the moment I still have to add the deletion of a single element and of the entire list while preloading of a whole list is under test .
If you use the ComboBox leaf as a simple menu of course you will have to enter in the code of the application or set the desired elements reading them from file at startup.
And i know also i have to increase distance of the items of the list to enable a better use by touch of the screen even if on my old GT P100 Samsung the selection works well.
The program works correctly on emulator 320x480 160dpi (base 1)
Have fun. (More detaill will follow)
Attachments
Last edited: