B4A Library [Class] SearchView - More powerful alternative to AutoCompleteEditText

Status
Not open for further replies.

padvou

Active Member
Licensed User
Thank you for the quick reply.
However, when i add a panel that is the same size as the searchview, the results that pop up cannot be shown. If I make a huge panel, they are shown. Is there aworkaround?
 

padvou

Active Member
Licensed User
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim SQL1 As SQL
Dim cursor1 As Cursor
Dim index1 As Object
Dim index2 As Object
Dim index3 As Object

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim SP_Start As Spinner
Dim SP_Start_valSelected
Dim Panel1 As Panel
Dim panel2 As Panel
Dim psv1 As Panel
Dim psv2 As Panel
'Dim psv3 As Panel
Dim LVDb As ListView
Dim cmdAdd As Button
Dim cmdDelete As Button
Dim cmdEdit As Button
Dim ID As String
Dim SelCustomer As SearchView
'Dim SelDescription As SearchView
Dim SelProduct As SearchView
Dim lbl_pro As Label
Dim lbl_cust As Label
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("orderentry")
If SQL1.IsInitialized = False Then
SQL1.Initialize(File.DirInternal, "client.db", False)
End If
SelCustomer.Initialize(Me,"SelCustomer")
SelProduct.Initialize(Me,"SelProduct")
'SelDescription.Initialize(Me,"SelDescription")



SelCustomer.AddToParent(panel2, 0,0, 200dip, 300dip)

SelProduct.AddToParent(Panel1, 0, 0, 200dip, 300dip)
'SelDescription.AddToParent(Activity, 450, 0, 200dip, 300dip)
If FirstTime Then
Dim List1 As List
Dim list2 As List
Dim list3 As List
List1.Initialize
list2.Initialize
'list3.Initialize


cursor1 = SQL1.ExecQuery("Select name, code,street1,city1,afm from customer")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
List1.Add(cursor1.GetString("name") & " " & cursor1.GetString("code"))

Next
index1 = SelCustomer.SetItems(List1)
cursor1 = SQL1.ExecQuery("select code,description, whsprice, rtlprice from material")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
list2.Add(cursor1.GetString("code") & " " & cursor1.GetString("description"))
'list3.Add(cursor1.GetString("description") & " " & cursor1.GetString("code"))
Next
index2 = SelProduct.SetItems(list2)
'index3 = SelDescription.SetItems(list3)



Else
SelCustomer.SetIndex(index1)

SelProduct.SetIndex(index2)
'SelDescription.SetIndex(index3)
End If

End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub OrderSave_Click
Panel1.RemoveView
SP_Start.visible=True
End Sub
Sub OrderSave_LongClick

End Sub
Sub SelUpd_Click

End Sub
Sub SelRem_Click

End Sub
Sub SelProduct_ItemClick (Value As String)

End Sub
Sub SelProduct_EnterPressed

End Sub
Sub SelDescription_ItemClick (Value As String)

End Sub
Sub SelDescription_EnterPressed

End Sub
Sub SelCustomer_ItemClick (Value As String)

End Sub
Sub SelAdd_Click

End Sub
Sub LVDb_ItemClick (Position As Int, Value As Object)

End Sub
Sub Panel2_Touch (Action As Int, X As Float, Y As Float)
lbl_cust.Text=SelCustomer
panel2.Visible=False

End Sub
Sub Panel2_Click

End Sub
Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
lbl_pro.Text=SelProduct
Panel1.Visible=False

End Sub
Sub Panel1_Click

End Sub
Sub lbl_Prod_Click
Panel1.Visible=True

End Sub
Sub lbl_Prod_LongClick

End Sub
Sub lbl_Cust_Click
panel2.Visible=True
End Sub
Sub lbl_Cust_LongClick

End Sub
 

Attachments

Roger Garstang

Well-Known Member
Licensed User
Advantages over AutoCompleteEditText:
  • SearchView also shows items that contain the input text (not just prefixes).
I'm not sure that is a difference. The AutoCompleteEditText does this. Having the index and ordering the results first by Prefix then by Containing is great though.
 

Erel

Administrator
Staff member
Licensed User
Sorry I meant a screenshot of the panel at runtime that shows the unwanted behavior.

@Roger Garstang, AutoCompleteEditText only finds items based on the prefix.
 

Roger Garstang

Well-Known Member
Licensed User
In my app I have a large list of Case Types in an Auto Complete Edit Text. Each Type has a Number and a Description like "1000 Robbery". They can type any part of the line and it will list the lines containing it. There may be different sub types too like "1001 Robbery - Bank" and such for almost a thousand entries. If I type "Rob" it comes back with a list containing all the Robbery types. I can type any part of the number too, like if I type "10" it will find 1000, 1010, 10, 2010, etc. I've been using it for some time and was actually impressed with that ability...that is how I know it did it.
 

Erel

Administrator
Staff member
Licensed User
AutoCompleteEditText does split words. However typing 10 will not return 2010.
 

Roger Garstang

Well-Known Member
Licensed User
AutoCompleteEditText does split words. However typing 10 will not return 2010.

OK, I see what you mean now. AutoCompleteEditText finds my results because it checks each word's prefix in my item text, but not within each of the words...only the beginning of each word (ex. If I type "obbery" from my example it finds nothing). Still better than Windows does. I'll have to check this out later for other views in my app. Currently AutoComplete works for my case types since they will usually know the words to type. This will work great for a search box or url....maybe even an instant message app.
 

roiuziel

Member
Licensed User
SearchView inside pannel or popup box

Hi,

I want to add a searchview inside a popup window or inside a pannel. Such that user presses a button and a searchview is popped up to select something from inside a list.

Is there a good example on how to do it?

Thanks,
Roi
 

Erel

Administrator
Staff member
Licensed User
(Have you read all forum posts before posting this question? Just kidding. He is my brother...)

You should add a panel to your layout and set its visibility to False. Add SearchView to the panel instead of the Activity:
B4X:
sv.AddToParent(Panel1, 0, 0, 200dip, 300dip)
You can then show the panel by changing its Visible property to True.

Note that you cannot add SearchView to a modal dialog (a dialog that stops program execution).
 

roiuziel

Member
Licensed User
Why do I have only one star under my name

As a family member, I'd like to have at least 3 stars under my name:sign0188:

Erel, please fix this bug.
 

roiuziel

Member
Licensed User
SearchView inside pannel or popup box

I already did the AddToParent(panel...). The problem is that the panel is in front view (probably with the search view inside) and when I try to press it and put text the main window behind it is getting the focus.

Maybe the question should be:
How do I write input into the searchview inside a panel which is not the main activity?

Thanks,
Roi
 

Erel

Administrator
Staff member
Licensed User
The search field is a regular EditText. You can add the FocusChanged event or call et.RequestFocus.
 

Erel

Administrator
Staff member
Licensed User
Is there any way to associate this search with the hardware search button?
You can intercept KeyCodes.KEYCODE_SEARCH in Activity_KeyPress.
 

Smee

Well-Known Member
Licensed User
i am trying to add a progressbar in place of
ProgressDialogShow2("Building index...", False)

i put this code here inside the sub

B4X:
Public Sub SetItems(Items As List) As Object
Main.pbIndexMax=Items.Size

...
..

   For i = 0 To Items.Size - 1
      If i Mod 100 = 0 Then DoEvents
      Main.pbCounter=i
      CallSub(Main,"UpdateProgressBar)
In main module Activity_Create I have this code by Klaus
B4X:
   ProgressBar1.Initialize("ProgressBar1")
   ProgressBar1.Visible=True
   ProgressBar1.Initialize("ProgressBar1")
   ProgressBar1.Visible=True
   Dim rflBar As Reflector
   rflBar.Target = ProgressBar1
   rflBar.RunMethod2("setMax", pbIndexMax, "java.lang.int")
However it is not working. I do not see any interactivity
 
Status
Not open for further replies.
Top