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

    Erel Administrator Staff Member Licensed User

    This is how progress bar looks on Android 4.
     
  2. madSac

    madSac Active Member Licensed User

    is there any method to load two items.Like contact name and phone number.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    You will need to modify the class in order to show two lines.
     
  4. pixelpop

    pixelpop Active Member Licensed User

    Erel,

    A user asked about using a delimited list, searching the first delimited item and returning the second. You said it would entail a change to the class.

    Support for two delimited items would be very useful. In my case, I have a list of airlines and their codes:

    British Airways,BA
    British Airways Shuttle,SHT
    British International,BS
    British North West Airlines,BNW
    Brussels Airlines,SN
    Brussels International Airlines,BXI
    Budapest Aircraft Service,BPS
    Buddha Air,BHA

    I need to display the airline name and return the airline code. Other uses might be name,email_addr or city,zipcode. Can you point me towards where the class mods need to be made to display only the first item and return the second item? Thanks.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You can load the data with StringUtils.LoadCSV. Then add the first items to SearchView.

    Use a Map to map between the first item and the second item.
     
  6. pixelpop

    pixelpop Active Member Licensed User

    Thanks for the help, Erel. I have loaded the csv file using:

    csv = su.LoadCSV(File.DirAssets, "all_airlines.txt", ",")

    Could you provide a line of code that will load the first items in csv into SearchView? I can manage the rest. Thanks!

    UPDATE: I didn't realize that a String variable could be an array. Quite a departure from VB, but all is good now. :)
     
    Last edited: Jan 31, 2013
  7. Tadder

    Tadder Member Licensed User

    loading 2 SV on 1 panel

    Hey Erel - I'm loading two SearchView's from a MySQL server and for some reason it's populating both with the same data set.

    here is the code, what's interesting is the DB data that gets loaded is the 2nd query statement... meaning if you switch the order (put conn first, then mfr) both lists show mfr records. the way it is written below shows the conn records, not the mfr.

    any help would be appreciated!
    Code:
    mfrSV.Initialize(Me,"mfrSV")
       
    Dim mfr As List = Main.serverDB.Query("SELECT mfrNum FROM products")
       mfrSV.AddToParent(pnl_searchconn,
    51%x,8%y,100%x,98%y)
       
       connSV.Initialize(Me,
    "connSV")
       
    Dim conn As List = Main.serverDB.Query("SELECT prodID FROM products")
       connSV.AddToParent(pnl_searchconn,
    2%x,8%y,48%x,100%y)
       
       
    If FirstTime Then
          mfrPNforSearch = mfrSV.SetItems(mfr)
          connPNforSearch = connSV.SetItems(conn)
       
    Else
          mfrSV.SetIndex(mfrPNforSearch)
          connSV.SetIndex(connPNforSearch)
       
    End If
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    I recommend you to use the web service approach for your code. Blocking the main thread will cause problems.

    Check:
    Code:
    Log(mfr)
    Log(conn)
    Are the values correct?
     
  9. Tadder

    Tadder Member Licensed User

    nothing showed up in the Log... weird. maybe because the variables are lists, and not strings?

    but in the debugger, the local variables did show that they were the same lists.

    Could you clarify what you mean for me please,

    and also what you mean by
     
  10. ikidd

    ikidd Member Licensed User

    I love this class, but I have issue with it when I've used it and then the operation panel comes up based on the picked item. If I try to go back and pick another item, I can type the new search term, and while I can't see the items list, I can still pick a line by tapping below.

    I'm sure it's something with background or foreground colors, but I can't see how I can get handles on the editText or the Listview that is inside SearchView to manipulate them and make them opaque.

    [​IMG]

    Once the ops panel is up, if I change the Searchview text, the items aren't visible through the ops panel, but can be chosen.

    [​IMG]

    How do I get the textbox handle and how do I put the list on top when it's active?
     

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    @Tadder, it seems like you are using a library that blocks the main thread. This will not work reliably. You should instead use a web service based solution as demonstrated in the MySQL or MS SQL tutorials.

    @ikidd, the problem if I understand correctly is that your panel hides SearchView panel. Why don't you hide this panel when the user enters any text in the SearchView field?
     
  12. Tadder

    Tadder Member Licensed User

    i don't understand what you mean by "blocks the main thread"... could you please explain, or point me in the right direction?

    i did get it to work, btw, just had to load the DB's one at a time..:
    Code:
    'LOAD THE FIRST LIST
       mfrSV.Initialize(Me,"mfrSV")
       
    Dim mfr As List = Main.serverDB.Query("SELECT mfrNum FROM products")
       mfrSV.AddToParent(pnl_searchconn,
    51%x,8%y,100%x,98%y)
       
    If FirstTime Then
          mfrPNforSearch = mfrSV.SetItems(mfr)
       
    Else
          mfrSV.SetIndex(mfrPNforSearch)
       
    End If
    'LOAD THE SECOND LIST
       connSV.Initialize(Me,"connSV")
       
    Dim conn As List = Main.serverDB.Query("SELECT prodID FROM products")
       connSV.AddToParent(pnl_searchconn,
    2%x,8%y,48%x,100%y)
       
    If FirstTime Then
          connPNforSearch = connSV.SetItems(conn)
       
    Else
          connSV.SetIndex(connPNforSearch)
       
    End If
    one issue though, it's pretty slow. suppose this has something to do with not using the web service you are describing?
     
  13. ikidd

    ikidd Member Licensed User

    Fair enough on the hide the panel.

    How do I grab the EditText handle inside the sv so I can reset it if the user doesn't choose a valid option?
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Change it to Public:
    Code:
    Sub Class_Globals
     
    Private et As EditText
     
  15. Tadder

    Tadder Member Licensed User

    So I switched out what I was using for the web service you told me to run. works 100 times better, thanks for that! i had looked at it at first a few weeks ago, but didn't understand it, and the one i was using was pretty simple (it seemed). which leads me to my next question...

    how do i use the searchview with a remote MySQL connection? i'm getting really confused about what happens when i call ExecuteRemoteQuery as far as what happens, and when it happens. for example:
    Code:
    connSV.Initialize(Me,"connSV")
    connSV.AddToParent(pnl_searchconn,
    51%x,8%y,100%x,98%y)
    query = 
    "SELECT prodID from PRODUCTS"
    ExecuteRemoteQuery(query,
    "LoadSVparts")
    If FirstTime Then
       connPNforSearch = connSV.SetItems(partslist)
    Else
       connSV.SetIndex(connPNforSearch)
    End If
    fyi, partslist is a global list that gets set in JobDone.

    This is erroring out because it gets to connSV.SetItems before it gets to initializing everything. how do i control the timing?
     
  16. Tadder

    Tadder Member Licensed User

    so here's my temporary fix, unless i don't get a suggestion, or figure it out myself. i was trying to load two SV's side-by-side - one with my p/n's and one with mfr p/n's. i don't understand the timing issues, but for the time being, i'm just grabbing both columns from the remote DB at the same time and then loading them into only one SV. like this (this code is in the JobDone Sub):
    Code:
    For i = 0 To SVParts.Size-1
       partsMap = SVParts.Get(i)
       partslist.Add(partsMap.Get(
    "prodID"))
       partslist.Add(partsMap.Get(
    "mfrNUM"))
    Next
    connPNforSearch = connSV.SetItems(partslist)
    problem is this doubles the size of the list (now totals 12000+ items), thus doubling the time it takes to initialize it... plus it has to re-do this everytime the user logs in (which i probably want to have happen anyway, as we'll be updating the DB daily :cool:). Using this method is OK for now, and it may not get any better.

    One other thing - it already takes about 10seconds to load (Building index... msg is up for about that long), and that is on Wifi with a 10meg cable modem... so i'm a little worried about someone that is connecting on 3G or worse...

    is there any way to speed up the loading time?
     
    Last edited: Mar 4, 2013
  17. Erel

    Erel Administrator Staff Member Licensed User

    You should fill the list in JobDone. The result is not available before.
     
  18. sanjibnanda

    sanjibnanda Active Member Licensed User

    search view with two views

    hello!

    i tried to populate two search view in same activity as

    Code:
    sv.Initialize(Me, "sv")
       
    sv1.Initialize(Me, 
    "sv1")
    it worked well,
    now i want to display different hint/control to edit box like

    Code:
    et.Hint="Delhi"
    but it display and pass control to both sv..and sv1 simultaneously

    how can two sv be handled separately with their independent control..plz advice

    sanjib
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    You should make et a public variable and change it from the activity code.
     
  20. sanjibnanda

    sanjibnanda Active Member Licensed User

    wow! thanks, you saved my day.
     
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