Android Question Adding Values Extracted from Sqlite Database to Autocomplete Edit Box

Rajesh Gupta

Member
Licensed User
I want to show the drop down list of autocomplete with the values extracted from DB, but there is an error when i am adding it to autocomplete.

My code:-

Sub ShowList

Dim SQL1 As SQL
Dim tblMasters As Cursor
Private ddlaccname As AutoCompleteEditText
Dim List1 As List
List1.Initialize
SQL1.Initialize(File.DirInternal, "Masters.db", True)

Dim q As String="Select * From tblMasters WHERE MType=2"
tblMasters=SQL1.ExecQuery(q)

ddlaccname.SetItems(tblMasters)

End Sub

Please Suggest some idea about the same.
 

LucaMs

Expert
Licensed User
Longtime User
SetItems requires a List and you are passing a SQL cursor!

You have to read the data, ONE FIELD, using the cursor and put them in a List.

B4X:
    Dim Cursor As Cursor
Dim lstData As List
lstData.Initialize
Dim q As String="Select * From tblMasters WHERE MType=2"
Cursor = SQL1.ExecQuery(q)
For i = 0 To Cursor.RowCount - 1
    Cursor.Position = i
    lstData.Add(Cursor.GetString("ChooseAFieldName"))
Next
ddlaccname.SetItems(lstData)
 
Upvote 0
Top