Android Question Spinner and sqlite

Mahares

Expert
Licensed User
Longtime User
How to display data from a field (sqlite) in a spinner?
This answers your question, but it is better to use B4XComboBox instead of spinner for x Platform
B4X:
strQuery = $"SELECT country FROM mytable ORDER BY country"$
    Dim rs As ResultSet = SQL1.ExecQuery(strQuery)    
    Do While rs.NextRow
        spinner.Add(rs.GetString("country") )
    Loop
    rs.Close
 
Upvote 0

Tata Mapassa

Member
Licensed User
Longtime User
I don't see how to use B4XComboBox with sqlite? I replaced spinner by B4XComboBox and I have errors.
Thank you for your help
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I don't see how to use B4XComboBox with sqlite? I replaced spinner by B4XComboBox and I have errors.
Thank you for your help

In that first post:

1664721162363.png
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I don't see how to use B4XComboBox with sqlite? I replaced spinner by B4XComboBox and I have errors.
Add B4XComboBox1 in the Designer . Make sure XUI Views library is checked
B4X:
Private B4XComboBox1 As B4XComboBox   'in globals, need the XUI Views library checked

B4X:
 strQuery = $"SELECT country FROM mytable ORDER BY country"$
    Dim rs As ResultSet = SQL1.ExecQuery(strQuery)    
    Do While rs.NextRow
       B4XComboBox1.cmbBox.Add(rs.GetString("country")    )
    Loop
    rs.Close
If you continue to have problems, post your code. You will get corrected and helped
 
Upvote 0

Tata Mapassa

Member
Licensed User
Longtime User
the code below works. Thank you :
Dim Cur As Cursor
Spinner2.Clear
Cur = SQL1.ExecQuery("SELECT * FROM Table")
For I = 0 To Cur.RowCount - 1
Cur.Position = I
Spinner2.Add(Cur.GetString("Field"))
Next
Cur.Close
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
the code below works. Thank you :
That's good that you got it. However you need to note a couple of things:
1. Use code tags when you post lines of code. It looks better and easier to follow.
2. It is preferable to use Resultset than cursor. So your code becomes:
B4X:
Dim Cur As Resultset
Spinner2.Clear
Cur = SQL1.ExecQuery("SELECT * FROM Table")
do while cur.nextrow
     Spinner2.Add(Cur.GetString("Field"))
loop
Cur.Close
 
Upvote 0

Similar Threads

Top