Hi to everybody
I have a list of strings and an EditText.
I would like that, as soon as the user writes something on the EdiText, a search is done on the list and, if any element of the List contains partially the entered text, this latter will be replaced by the List element.
The idea is explained in the attached project. Here we have an EditText and a Label. The Label changes, of course. The problem is to change the EditText, (for obvious reasons).
Thanks for any hint.
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim ListaPunti As List
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private EditText1 As EditText
Private Label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
ListaPunti.Initialize
ListaPunti.Add("1111")
ListaPunti.Add("2222")
ListaPunti.Add("3333")
ListaPunti.Add("4444")
ListaPunti.Add("5555")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub EditText1_TextChanged (Old As String, New As String)
Label1.Text=""
If ListaPunti.IsInitialized Then
For Each b As String In ListaPunti
If b.Contains(New) Then
Label1.Text=b
Exit
End If
Next
End If
End Sub
Hi. I have an additional question: as soon as I digit a part of an existing name, the autocomplete works. Let's suppose to have also a Button that needs the entire name (I just wrote a part of it, and the Button is pressed just after my partial input of the name): ho to get the entire autocompleted text? I attach a modified version of my code, using SuggestionText, to eplain the question.
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim ListaPunti As List
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private EditText1 As SuggestionsEditText
Private Label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
'EditText1.GetForegroundEditText.Hint = "City"
ListaPunti.Initialize
ListaPunti.Add("1111")
ListaPunti.Add("1222")
ListaPunti.Add("1333")
ListaPunti.Add("1244")
ListaPunti.Add("2555")
EditText1.DeleteAllWordsDBs("")
EditText1.InitWordsDB
EditText1.AddAll(ListaPunti)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub Button1_Click
Label1.Text=EditText1.Text ' ???
End Sub
I have some names in a list. The user writes a part of the name. The entire name appears (without the user writes it completely). So, when the user sees the correct name, he can press the button to accept it. That's all. Thanks
What you want, referring to the example, is that if the user types 12, 1222 is suggested, and there is a second item, 1244.
The user presses the button, and the view should display 1222 as the final entry, which can be retrieved with EditText1.Text <--- currently this only values 12.
I saw that the text is completed/confirmed when you press "Enter" on the keyboard, which does what you want a button to do.
If you want, I can change it anyway, but is it worth it? Isn't it better to have one less button?
[It only takes me a second to make the change; I just need to change the scope of a Sub from Private to Public. The "longest" time would be compiling and publishing, that's all].
I saw that the text is completed/confirmed when you press "Enter" on the keyboard, which does what you want a button to do.
If you want, I can change it anyway, but is it worth it? Isn't it better to have one less button?
[It only takes me a second to make the change; I just need to change the scope of a Sub from Private to Public. The "longest" time would be compiling and publishing, that's all].
Si, mannaggia, stavo per ringraziarti pubblicamente e, cosa rara, sono stato interrotto da una telefonata! Yes, I was about to thank you publicly and, rare thing, I was interrupted by a phone call!
REALE - andato in alla!!! cucina, versato dalla MOKA e scaldato al microonde! NON ti stavo chiedendo una donazione, maremma decaffeinata REAL - went to the kitchen, poured from the MOKA pot, and heated in the microwave! I was NOT asking for a donation, "maremma decaffeinata"!
Ti ringrazio, vorrà dire che con la donazione comprerò pacchetti di caffè per un mese (credo, boh). Thank you, it will mean that with the donation I will buy packets of coffee for a month (maybe, who knows).
Only another suggestion, due to my tests. When we use ConfirmWord, the cursor goes to the beginning of the EditText. I think (but not totally sure) that if the cursor goes to the end could be better.
Only another suggestion, due to my tests. When we use ConfirmWord, the cursor goes to the beginning of the EditText. I think (but not totally sure) that if the cursor goes to the end could be better.
Since the user has accepted the "suggestion", he will most likely keep it as is and move on to another input field, OR he may have changed his mind or wanted to choose a word/phrase, so perhaps it would be better to have all the text automatically selected and the cursor at the beginning, so that if he starts typing, whatever is already in the EditText will be deleted and the automatic search will be started.
(Certo che in italiano è "leggermente" più facile )