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

Status
Not open for further replies.
Edit: better to use B4XDialog + B4XSearchTemplate

SearchView is made of an EditText and ListView. When the user enters text into the EditText the ListView shows the items that start with this text or that contain the text (in this order).

This view is useful for allowing the user to select an item from many items.

Advantages over AutoCompleteEditText:
  • SearchView uses an internal index that is built when you call SetItems. This allows it to quickly find the matches.
  • SearchView also shows items that contain the input text (not just prefixes).
  • The class code can be further customized as needed.

upload_2017-2-21_17-48-19.png


Tutorial about handling large, searchable lists: https://www.b4x.com/android/forum/t...e-list-with-searchview-b4xserializator.61872/
 

Attachments

  • SearchView.zip
    45.1 KB · Views: 1,205
Last edited:

achtrade

Active Member
Licensed User
How can this SearchView be filled with data from a SQLite database ?

a piece of code should be highly thankful
 

achtrade

Active Member
Licensed User
You need to create a list with the items you want to show in SearchView.

For example:
B4X:
Dim items As List
items.Initialize
For Each row() As String In DBUtils.ExecuteMemoryTable(SQL, "SELECT name FROM table1", Null, 0)
items.Add(row(0))
Next
sv.SetItems(items)

Thanks Erel, that worked. But I post the question in the wrong threat, I wanted to asked it here:

https://www.b4x.com/android/forum/t...e-list-with-searchview-b4xserializator.61872/

can I ask again in that threat ?
 

achtrade

Active Member
Licensed User
I have a second EditText below the first one, when I start to type in the first ET and the list shows up, I can't select the item in front the second ET, instead, the second ET got the focus without select any item from the first list.

How can I fix this ?
 

achtrade

Active Member
Licensed User
Are you calling SearchView.AddToParent after the second EditText is added?

This is my code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    lblCustomer.Initialize("")
    lblCustomer.Text = "Customer"
    lblProd.Initialize("")
    lblProd.Text = "Product"

    Panel1.AddView (lblCustomer, 5%x, 5%y, 200dip, 300dip)

   'first searchview
    sv.Initialize(Me, "sv")
    sv.et.Hint="search customers"
    sv.AddToParent(Panel1, lblCustomer.Width, 5%y, 300dip, 300dip)

  'second searchview
    Panel1.AddView (lblProd, 5%x, 15%y, 200dip, 300dip)
    sv2.Initialize(Me, "sv2")
    sv2.et.Hint="search products"
    sv2.AddToParent(Panel1, lblCustomer.Width, 15%y, 300dip, 300dip)
end sub

that's all
 

achtrade

Active Member
Licensed User
this is how the screen looks
 

Attachments

  • Screenshot_2016-10-18-20-30-53.png
    Screenshot_2016-10-18-20-30-53.png
    56 KB · Views: 152

jayel

Active Member
Licensed User
Erel,

I am strungling with the searchview, as is, it works, but I have to return the index of th choosen item from the original list, so I can look in another list of maps to return the id.
How can I do that?

greets

John
 

LucaMs

Expert
Licensed User
You could add this code, to be able to use this view also on a smartphone in landscape mode (little space for the Listview, but it is better than nothing. I just created a similar Custom View, without ListView; I have yet to test it well and it has a small inconvenience of use for which I'll ask you a suggestion, though I think there's not an ideal solution).
 
Last edited:

Peter Lewis

Active Member
Licensed User
HI All, I am finding that once I have used the selection and passed the values to another Activity ( After the other activity the workflow goes back to the main activity) , The selected value appears the next time I go back into that Activity. Is there anyway of clearing that , and when should I clear it.

I put message boxes all over to see where the flow goes and it comes back to Activity Resume, If I use the back key and use SearchView again , it goes back to Activity Create and then it is cleared.

Any ideas would be useful. Thank you
 

achtrade

Active Member
Licensed User
I have a CLV and a SearchView inside a panel, when I'm typing in the edittext the result of the searchview is behind the CLV, I can't see it. How to bring the result of the searchview in front the CLV ?
 
Last edited:
Status
Not open for further replies.
Top