Italian SQLLite e dati in ListView

Ennesima77

Member
Licensed User
Longtime User
Ciao a tutti,
sono un neofita che più neofita non si può, anche se conosco qualcosaina di Visual Basic dalla versione 6 alla .net.
Ho iniziato a smacchinare con Basic4Android e volevo riempire una ListView con dati prelevati direttamente da una chiamata SQL. A tale scopo ho usato questa sintarsi:
DBUtils.ExecuteListView(SQLDB,"select FullName, PlayerID from players",Null,0,lwPlayers,False)
e funziona correttamente, il problema che io vorrei reperire il PlayerID dalla ListView, ma se vado in ListView_Click il Value è restituito un valore strano che non riesco ad interpretare.

Avevo trovato un treath che ne parlava in inglese, ma non c'era risposta.
Riuscite ad aiutarmi?:sign0085:

Grazie e buona giornata.
 

Ennesima77

Member
Licensed User
Longtime User
in Activity_Create ho inserito questo:

SQLDB.Initialize(File.DirDefaultExternal,"FlorManager.sqlite",False)
DBUtils.ExecuteListView(SQLDB,"select FullName, PlayerID from players",Null,0,lwPlayers,False)


ed ho aggiunto il seguente codice:

Sub lwPlayers_ItemClick (Position As Int, Value As Object)

Msgbox(lwPlayers.GetItem(Position),"Valore")

'Msgbox(Value(0) & CRLF & Value(1) & CRLF & Position,"Testo")

End Sub


il risultato ottenuto è quello in allegato, ma seconda riga non viene compilata in quanto mi dà una serie di errori.
 

Attachments

  • Nuova immagine bitmap.jpg
    74.9 KB · Views: 239

klaus

Expert
Licensed User
Longtime User
Try following code:
B4X:
DBUtils.ExecuteListView(SQLDB,"select PlayerID, FullName  from players", Null, 0, lwPlayers, True)
You must set the last parameter to True for two lines ListView.
Swap FullName and PlayerID to have the PlayerID in the first line as the return value.
And
B4X:
Sub lwPlayers_ItemClick (Position As Int, Value As Object)
    Msgbox(lwPlayers.Value, "Valore")
End Sub
Sorry, it's in english.

Best regards.
 

Ennesima77

Member
Licensed User
Longtime User

klaus

Expert
Licensed User
Longtime User
Sorry, I didn't look carefully enough.
DBUtils uses AddTwoLines2 so the return value is an Object.
The codes below work:
B4X:
DBUtils.ExecuteListView(SQLDB,"select FullName, PlayerID  from players", Null, 0, lwPlayers, True)
B4X:
Sub lwPlayers_ItemClick (Position As Int, Value As Object)
    Dim Valore(2) As String
    Valore = Value
    Msgbox(Valore(0) & "  " & Valore(1), "Valore")
End Sub
I tried a similar code as the one posted and got the same problem, so I looked deeper inside.

Best regards.
 

Ennesima77

Member
Licensed User
Longtime User
Thanks a lot it works fine!!!!!!
 

Ennesima77

Member
Licensed User
Longtime User
Giusto un'altra curiosità.
Nel progetto ho aggiunto file SQLLite, che però non si aggiorna!
Mi spiego meglio: se faccio delle modifiche nel DB (uso SQLLite Manager di Firefox) il file non viene poi riportato nel dispositivo e rimane il vecchio.
Per il momento l'ho copiato a manina, ma esiste un modo per far vedere in automatico l'aggiornamento del file?

I try to translateit best as I can.
In my project I had add an SQLLite file.
I use SQLLite Manager in Mozzilla Firefox to manage and edit the file (add column, new table, etc.)
When I do any kind of edit it doesn't update in the device, and use always old version.
I tried to delete and then attach again the file from "File panell" but it doesn' work.

Any Idea????

Thanks
 

Ennesima77

Member
Licensed User
Longtime User
I don't use any particular code, just a activity_create I have had
DBUtils.CopyDBFromAssets("FlorManager.sqlite")
to pickup the db from the project.

In the attachment you can see also the file in mty project.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Do you test if the file already exists on the SD card?
If no every time you run the program you copy the DB from DirAssets.

Did you have a look at chapter 5 in the User's Guide especialy page 20 ?
In the code example from page 20 you can replace
File.Copy(File.DirAssets, DBFileName, DBFileDir, DBFileName)
by
DBUtils.CopyDBFromAssets("FlorManager.sqlite")
You must also adapt the variables to your project.

Best regards.
 

Ennesima77

Member
Licensed User
Longtime User
I try to use the code in capter 5, but I need to delete manully the file from the device to update it.
It's not a big problem.
Thanks a lot for you reply.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…