B4A Library [Custom View] SuggestionsEditText

LucaMs

Expert
Licensed User
I needed an EditText like SearchView but without the list shown (without ListView), to use it on a smartphone in landscape mode (you know, in this situation the keyboard takes up almost the available space).

This view uses a SQLite DB to store the words and to retrieve them typing the first characters.

To be able to delete all the old and unneeded db files, you must call the DeleteAllWordsDBs method once, before doing anything else with the custom view. With this method you also set the DB's directory.

After this, you must initialize the SuggestionsEditText DB calling its method InitWordsDB.


I'll update soon this post with details about methods and properties ;) but they are documented and easy to understand.

Don't forget that this is a TOTALLY FREE library, so... don't be too bad with your comments and too stingy to click on "Like" :D


SuggetionsEditText.gif


Members: https://www.b4x.com/android/forum/threads/custom-view-suggestionsedittext.77776/#post-493565


Added V. 1.1

Method: InitWordsDB2(SuggET As SuggestionsEditText)
To use the same DB of another SuggestionsEditText view.

Property: DB
To get the words DB associated.



Added V. 1.3

Method: AddAllAsync (lstWords As List)

Properties: HintText, KBSuggestions

Event: AddAllAsyncComplete



Version 2.0

Previous versions use internally:

https://developer.android.com/refer...method/EditorInfo.html#IME_FLAG_NO_EXTRACT_UI

upload_2017-4-9_18-3-15.png



I saw this now only, so v. 2.0 uses:

upload_2017-4-9_18-6-6.png


[Note that IME_FLAG_NO_FULLSCREEN needs API 11 and above]

Also, added:

Property: KBFullScreen
 

Attachments

Last edited:

LucaMs

Expert
Licensed User
This Custom View does not get much interest, I would say (I hope only because of its name. Its name may suggest the classic hint of EditText but it is not so and the classic hint is still available, for its different purpose. The name of this Custom View should be AutoCompleteEditText or AutoCompleteView, but then it would be confused with existing ones).

Despite this, since I promised to add a minimum of documentation...


Use cases: as mentioned, lack of space for use Views like SearchView (space for the ListView; mainly on smatphones in landscape). So, same use cases of SearchView.


METHODS (alphabetical order):

Add (Word As String):
Allows you to add a single word (text line) to the "list" (db table).
Ex: SuggestionsEditText1.Add("Sarchiapone nano")

AddAll (lstWords As List):
Allows you to add a list of words.
Ex: SuggestionsEditText1.Add(Array As String("Sarchiapone nano", "Gatto", "Cane"))
Ex2: SuggestionsEditText1.Add(lstAnimals) [where lstAnimals is a List object, of course]

V. 1.3
AddAllAsync (lstWords As List):

Same as AddAll but this uses the asynchronous SQLite method AddNonQueryToBatch.
Raises the AddAllAsyncComplete event.
Ex: SuggestionsEditText1.AddAllAsync(Array As String("Sarchiapone nano", "Gatto", "Cane"))
Ex2: SuggestionsEditText1.AddAllAsync(lstAnimals) [where lstAnimals is a List object, of course]

AddToParent (Parent As View, Left As Int, Top As Int, Width As Int, Height As Int):
Allows you to add a SuggestionsEditText by code instead of by Designer.
Ex: SuggestionsEditText1.AddToParent(Panel1, 0, 0, 50%x, 50dip)

Contains (Word As String) As Boolean [function]:
To know if the specified word is already in the "list" (db table).
Ex: If SuggestionsEditText1.Contains("Dog") = True Then...

DeleteAllWordsDBs (Dir As String):
Deletes all old, unneeded db files previously associated to all your SuggestionsEditText views.
You should invoke this method once and before all other "operations" on SuggestionsEditText views.
Also, Dir will be the directory where db files will be saved.
Ex: SuggestionsEditText1.DeleteAllWordsDBs("") - Null String implies File.DirInternal.

GetBackgroundEditText:
Allows you to get the background EditText, used "as base" of SuggestionsEditText, to change its all properties .
Ex: Dim ET As EditText = SuggestionsEditText1.GetBackgroundEditText

GetBase:
To get the panel used as base of any CustomView (added by Designer)
Ex: Dim pnlBase As Panel = SuggestionsEditText1.GetBase

GetForegroundEditText:
To get the foreground EditText, which will contain the text entered by the user.
Ex: Dim ET As EditText = SuggestionsEditText1.GetForegroundEditText

InitWordsDB:
Initializes the DB associated to the SuggestionsEditText.
Ex: SuggestionsEditText1.InitWordsDB

V. 1.1
InitWordsDB2(SuggET As SuggestionsEditText):
Allows you to use the DB of the specified SuggestionsEditText.
Ex: SuggestionsEditText2.InitWordsDB(SuggestionsEditText1)

RemoveAllWords:
Removes all words saved for that SuggestionsEditText.
Ex: SuggestionsEditText1.RemoveAllWords

RemoveWord (Word As String):
Removes the specified word.
Ex: SuggestionsEditText1.Remove("Cat")




PROPERTIES (alphabetical order):

BackTextColor:

Sets / Gets the color used for the suggestion text.
Ex: SuggestionsEditText1.BackTextColor = Colors.Gray

CaseSensitive:
Sets / Gets if the search taking in account lowercase and uppercase or not.
Ex: SuggestionsEditText1.CaseSensitive = True

Color:
Same Color property of any other B4X view, so:
View attachment 54251
The color will be applied to the BackgroundEditText (the ForegroundEditText color is transparent)

V. 1.1
DB:
Gets the DB associated to the SuggestionsEditText.
Ex: Dim SQL1 As SQL = SuggestionsEditText1.DB

DBDir:
Gets the Directory which contains the DB associated to the SuggestionsEditText.
Ex: Dim DBFolder As String = SuggestionsEditText1.DBDir

DBFileName:
Gets the file name of the DB associated to the SuggestionsEditText.
Ex: Dim DBFileName As String = SuggestionsEditText1.DBFileName

ForceDoneButton:
Forces Android to display Done as Action Key in the virtual keyboard.
Ex: SuggestionsEditText1.ForceDoneButton = True

V. 1.3
HintText:
Same Hint Text property of EditTexts.

InDBOnly:
Used to set if any words will be accepted or only those present in the db table.
Ex: SuggestionsEditText1.InDBOnly = True

V. 2.0
KBFullScreen:
Sets Keyboard full screen on/off

V. 1.3
KBSuggestions:
Sets the Keyboard's suggestions on/off

Text:
Same Text property of any other B4X view. The Foreground text will be set.

TextColor:
Same TextColor property of any other B4X view. The Foreground text color will be set.



Events:
TextChanged, EnterPressed and FocusChanged: same events of B4a EditText view.

V. 1.3
AddAllAsyncComplete (Success As Boolean)
Raised by the AddAllAsync method.
 
Last edited:
Top