List view problem

cirollo

Active Member
Licensed User
Longtime User
Hi!

I'm having a problem with a listview, following the two activities tutorial, I've made two modules,
the first, clicking on a button, starts the second activity with a listview on it.

this is my code for the first activity (Prodotti):

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Prodotti")
   SpCodDes.AddAll(Array As String("Codice","Descrizione"))
   DBUtils.ExecuteSpinner(SQL, "SELECT Famiglia FROM Famiglie order by Famiglia", Null, 0, SpFamiglia)
'   DBUtils.ExecuteSpinner(SQL, "SELECT GruMer FROM Gruppi order by GruMer", Null, 0, SpGrumer)
   'Scelgo un record dallo spinner
   'SpArticoli_ItemClick(0, SpArticoli.GetItem(0))
End Sub

Sub Activity_Resume
    If RicercaProdotti.result.Length > 0 Then
        TxtCodice.Text = "" & RicercaProdotti.result
    Else
        TxtCodice.Text = " "
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub BtnRicerca_Click
   StartActivity(RicercaProdotti)
End Sub

an this is my second activity code (RicercaProdotti):

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
    Dim result As String
    result = ""
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim SQL As SQL
   SQL = Main.SQL
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("RicercaProdotti")
   ListView1.Initialize(ListView1)
    ListView1.TwoLinesLayout.ItemHeight = 70dip
    ListView1.TwoLinesLayout.Label.TextSize = 20
   ListView1.FastScrollEnabled = True
   ListView1.Color = Colors.Black
   ListView1.ScrollingBackgroundColor = Colors.Black
   Dim cur As Cursor
     cur = SQL.ExecQuery("SELECT IdArt,Desart FROM Articoli")
    For i = 0 To cur.RowCount-1
         cur.Position = i
   '    ListView1.AddSingleLine(cur.GetString("IdArt"))
       ListView1.AddTwoLines(cur.GetString("IdArt"),cur.GetString("Desart"))
   Next
End Sub

Sub Activity_Resume

End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
   result = value 'store the value in the process global object.
    StartActivity(Prodotti) 'show the main activity again
End Sub

the problem is that on the second activity the list view is always empty! it seems the SQL query failed, and It's strange.

I've tried to use only one activity showing the listview with

Activity.AddView(ListView1, 0, 0, 100%x, 100%y)

and the record are shown but I don't know how to retrieve the selected item (the Listview1_Itemclick doesn't work) so I tried the two activities method.

I would like to know if is possible to use only one activity and return the selected item or, otherwise, why no record is shown on the listview1 on the second activity!

sorry but I'm a beginner with B4A :sign0104:
 

cirollo

Active Member
Licensed User
Longtime User
tried but...

the listview is still empty!

but the records in the db there are!!!!!

Should I check something else????

SOLVED

I need: Activity.AddView(ListView1, 0, 0, 100%x, 100%y)
 
Last edited:
Upvote 0

parijs

Active Member
Licensed User
Longtime User
This is my solution for creating a Favorites view, you can also delete a view


Dim cur As Cursor
Dim q As String
SQL.Initialize(File.DirRootExternal, "VisitParijs/visit.db", False)
cur = SQL.ExecQuery("SELECT MapNaam, keuze, Regelonder, pic, picbit FROM favo")

For i = 0 To intCount -1
cur.Position = i

mapc(i) = main.MapNaam
favot(i) = main.keuze

Dim picbt As Bitmap
Bitmap1.Initialize(File.DirAssets, main.pic)

ListView1.AddTwoLinesAndBitmap(cur.GetString("MapNaam"), cur.GetString("Regelonder"), Bitmap1)
Next

Activity.AddView(ListView1, 0, 60, 100%x, 90%y)

Sub ListView1_ItemClick (Position As Int, Value As Object)
If Value = mapc(0) Then
main.keuze=favot(0)
Kode.Telme
End If

Sub ListView1_ItemLongClick (Position As Int, Value As Object)
SQL.Initialize(File.DirRootExternal, "VisitParijs/visit.db", False)

If Value = mapc(0) Then
SQL.ExecNonQuery("DELETE FROM favo WHERE keuze = '" & favot(0) & "'")
End If


With a little help from my friends :)
 
Upvote 0
Top