Android Question SearchView like view, but with more than 1 column

Discussion in 'Android Questions' started by Anser, Sep 22, 2015.

  1. Anser

    Anser Well-Known Member Licensed User

    Dear Friends,

    The scenario:-

    In my app, there are 2 EditText views (EditText_ItemCode and EditText_ItemName) where the user has to pick the ItemCode from a list of Items. The SearchView list should show the ItemCode as well as ItemName in a row just like a grid wth 2 columns.

    When the user choose an Item the ItemCode should be returned to EditText_ItemCode view. If possible EditText_ItemName should get the ItemName too. I know that, if, I can get the ItemCode, then I can do another query to the MySQL database and then get the ItemName, I am just checking whether this can be done without raising another query to the remote MySQL server.

    Some of my app users will be familiar with the ItemCode, but some may not be familiar with the ItemCodes, so they find ItemName or ItemDesctiption easier. That's the reason for the need to show both the columns on the SearchView

    • The database is remote MySQL server connected via RDC
    • The no of items in the list will be more than 25000
    I am looking for a view similar to SearchView, but understand that SearchView can only show the data as a single column.

    Is there any other view available which can be used to do the above said task. The control should handle a list of more than 25000 items efficiently and quickly.

    Any suggestions/help will be appreciated.

    Last edited: Sep 22, 2015
  2. Anser

    Anser Well-Known Member Licensed User

    Anyone, any idea about a lib that works as explained above ?

    At times, I may require to return both the ItemCode and ItemName
  3. Anser

    Anser Well-Known Member Licensed User

    Is it possible to implement this with SearchView ie Display ItemName and search on ItemName and when clicked Return the ItemCode of that particular ItemName to some variable in the Activity.

    In the SearchView, the ItemNames are assigned to the SearchView by using a List, how can I use this to add the ItemCode too. I don't want the user to see the ItemCode and I don't want search on ItemCode.

    Any help will be appreciated. I am stuck with my project.
  4. LucaMs

    LucaMs Expert Licensed User

    I think you cannot avoid to query your db otherwise you need to fill two views (whatever they may be) with 25,000 x 2 items!
  5. Anser

    Anser Well-Known Member Licensed User

    For the time being, to get me moving in my project, what I was thinking was about the possibility of adding 2 elements to the List that is used in the SearchView
    ie ItemName and ItemCode. I know that with this solution I cannot display both the ItemName and ItemCode to the user, instead ItemName can be shown to the user and when the user clicks on the ItemName, ItemCode canbe assigned/retrieved to some variable in the Activity Module

    For eg. in the section where I fill data to the SearchView
    ' Fill the SearchView with the required data
    Sub FillSvItemsList(result As DBResult)
    For Each records() As Object In result.Rows
    'StockItemsList.Add( records(result.Columns.Get("StockItems_Name")) )
            MyRow() As String
            Row = (records(result.Columns.Get(
    "StockItems_Name")), records(result.Columns.Get("StockItems_Code")) )
            StockItemsList.Add( MyRow )
        svStockItemsListIndex = svStockItemsName.SetItems(StockItemsList)
    End Sub
    Then in the SearchView module, I will add a Public Variable to hold the ItemCode of the chosen/clicked item
    For eg
    Public MyVarToHoldStockItemCode as String
    And in my Activity Module, I will try to access the Code something as follows
    Sub svStockItemsName_ItemClick (Value As String)
        cItemName = Value
        cItemCode = svStockItemsName.MyVarToHoldStockItemCode
    End Sub
    Still puzzled with how to code this in SearchView Module's following Sub's
    Public Sub SetItems(Items As ListAs Object
    Private Sub AddItemsToList(li As List, full As String)
    Private Sub lv_ItemClick (Position As Int, Value As Object)
       et.Text = Value
       et.SelectionStart = et.Text.Length
    Dim IME As IME
       lv.Visible = 
    If SubExists(mCallback, mEventName & "_ItemClick"Then
    CallSub2(mCallback, mEventName & "_ItemClick", Value)
    End If
    End Sub
    I don't know whether I am moving in the right direction.

    But I still wonder, why such an inbuilt view is not available in B4A environment. Am I, the only person with such a requirement?. In other application development tools that I have used, I never had to spend time on building such views/control, and I could concentrate on developing my business app rather than creating the tools.
    Last edited: Oct 17, 2015
  6. Anser

    Anser Well-Known Member Licensed User

    The above said logic works. Even though there are few minor issues, Got it working. :)

    Not sure whether this is the right way or not, OR exist other better and elegant solutions.

    Hope this would be helpful for other newbies like me.

  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