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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 8, 2012.

Thread Status:
Not open for further replies.
  1. padvou

    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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post a screenshot and the code?
     
  3. padvou

    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
     

    Attached Files:

  4. Roger Garstang

    Roger Garstang Well-Known Member Licensed User

    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.
     
  5. Erel

    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.
     
  6. Roger Garstang

    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.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    AutoCompleteEditText does split words. However typing 10 will not return 2010.
     
  8. Roger Garstang

    Roger Garstang Well-Known Member Licensed User


    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.
     
  9. roiuziel

    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
     
  10. Erel

    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:
    Code:
    sv.AddToParent(Panel1, 00200dip300dip)
    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).
     
  11. roiuziel

    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.
     
  12. roiuziel

    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
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Try the attached example. It shows the Panel with SearchView when you press the button.
     

    Attached Files:

  14. Smee

    Smee Well-Known Member Licensed User

    Is it possible to detect when a searchview has the focus or set focus?
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    The search field is a regular EditText. You can add the FocusChanged event or call et.RequestFocus.
     
  16. airblaster

    airblaster Active Member Licensed User

    Is there any way to associate this search with the hardware search button?
     
  17. Smee

    Smee Well-Known Member Licensed User

    Ahhhhhh yes i see now. thank you
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    You can intercept KeyCodes.KEYCODE_SEARCH in Activity_KeyPress.
     
  19. Smee

    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

    Code:
    Public Sub SetItems(Items As ListAs 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
    Code:
    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
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    Where is UpdateProgressBar sub?
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice