Android Question Have NULL as first element of an spinner loaded with SQL

Discussion in 'Android Questions' started by FERNANDO SILVEIRA, Jun 3, 2018.

  1. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Hello Guys,

    I'm loading a spinner from SQL database but I'd like to have the very 1st spinner element as NULL (or space) and give the chance the user to pick up NULL if none of the existing values applies to him.

    What is the best aproach? To have DBUtils.ExecuteSpinner load spinner and then FOR/NEXT loop to shift all elements by 1 and set NULL to the list(0)?

    Is there a smarter way of doing this?

    Regards,
    Fernando
     
  2. Mahares

    Mahares Well Known Member Licensed User

    In this case add the first element of the spinner as a space, followed by the cursor resultset to continue to populate the spinner.
    Code:
    Dim spn As Spinner
        
    Dim txt As String
        
    Dim cursor1 As Cursor
        spn.Add(
    " ")  '1st spinner record
        txt="SELECT COUNTRY FROM mytable ORDER BY COUNTRY"
        cursor1=SQL1.ExecQuery(txt)
        
    For i=0 To cursor1.RowCount-1
            cursor1.Position=i
            spn.Add(cursor1.GetString(
    "COUNTRY") )
        
    Next
        cursor1.close
     
    FERNANDO SILVEIRA likes this.
  3. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User


    Thanx, Mahares, but I took the liberty of changing DBUtils.ExecuteSpinner instead and added a parameter named FIRSTNULL, keeping evething else untouched. See new code below:

    Code:
    'Executes the query and fills the Spinner with the values in the first column
    Sub ExecuteSpinner(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Spinner1 As Spinner, firstNull As Boolean)
        Spinner1.Clear
        
    If firstNull Then Spinner1.Add(" ")    ' <== Fernando Silveira: Leave 1st element EMPTY
        Dim Table As List
        Table = ExecuteMemoryTable(
    SQL, Query, StringArgs, Limit)
        
    Dim Cols() As String
        
    For i = 0 To Table.Size - 1
            Cols = Table.Get(i)
            Spinner1.Add(Cols(
    0))
        
    Next
    End Sub
     
    Mahares likes this.
  4. udg

    udg Expert Licensed User

    IMHO, modifying a "standard" class is generally not a good idea. Think of when an update will be available..you'll have to reply all the modifications you did on its previous version.
     
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