help for sql lite important

alim2012

Member
Licensed User
Longtime User
hi all
i write this code :

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

Dim s As SQL
Dim c As Cursor
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("download")
If File.Exists(File.DirDefaultExternal,"marja.db") = False Then
   File.Copy(File.DirAssets,"marja.db",File.DirDefaultExternal,"marja.db")
End If
s.Initialize(File.DirDefaultExternal, "marja.db",False)

c=s.ExecQuery("SELECT title,id FROM category")
For i=0 To c.RowCount-1
c.Position=i
ListView1.AddSingleLine(c.GetString("title"))
Next
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
c=s.ExecQuery("SELECT title,id FROM category WHERE title=" & "'" & Value & "'")
For i=0 To c.RowCount-1
c.Position=i
ListView1.AddSingleLine(c.GetString("id"))
Next
End Sub

if exist duplicate name for title how give id
any idea?
please help me please...

thanks a lot
:BangHead::BangHead::BangHead:
 

klaus

Expert
Licensed User
Longtime User
I don't understand what exactly you want to do with the code?
in your code if there is a double title you add the id at the end of the ListView ???
What do you expect when clicking on an item in the ListView ?
Depending on what you want to do the code might be different.

If you want to get the id you should use
ListView1.AddSingleLine2(c.GetString("title"), c.GetInt("id"))
in this case the return value is the id.

Best regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…