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):
an this is my second activity code (RicercaProdotti):
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:
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: