Android Question Listview itemclick event does not raise

cirollo

Active Member
Licensed User
Longtime User
this is my code, the msgbox doesn't appear....
tried to remove and insert again the listview, the event is created from object designer...

why????

B4X:
#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: False
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

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 SQL1 As SQL        :SQL1 = Main.SQL1
   Private SpScuola As Spinner
   Private SpClasse As Spinner
   Private SpSezione As Spinner
   Private LstAlunni As ListView
   Dim bmpGrn As Bitmap
   Dim bmpRed As Bitmap
'   Private PnlDett As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("rilevazione")
   'devo riempire lo spinner scuole
   SpScuola.Add(" ")
   Dim Cur As Cursor
   Cur = SQL1.ExecQuery("SELECT distinct DesScuola FROM Anagrafiche order by Scuola")
   For i = 0 To Cur.RowCount-1
     Cur.Position = i
         SpScuola.Add(Cur.GetString("DesScuola"))
     Next
   Cur.Close
   SpScuola.SelectedIndex=0
'   PnlDett.Visible = False
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SpScuola_ItemClick (Position As Int, Value As Object)
   'devo riempire lo spinner classi
   SpClasse.Clear
   SpSezione.Clear
   LstAlunni.Clear
   SpClasse.Add(" ")
   Dim Cur As Cursor
   Cur = SQL1.ExecQuery("SELECT distinct Classe FROM Anagrafiche where DesScuola='"&SpScuola.SelectedItem&"' order by Classe")
   For i = 0 To Cur.RowCount-1
     Cur.Position = i
         SpClasse.Add(Cur.GetString("Classe"))
     Next
   Cur.Close
   SpClasse.SelectedIndex=0
End Sub

Sub SpClasse_ItemClick (Position As Int, Value As Object)
   'devo riempire lo spinner sezioni
   SpSezione.Clear
   LstAlunni.Clear
   SpSezione.Add(" ")
   Dim Cur As Cursor
   Cur = SQL1.ExecQuery("SELECT distinct Sezione FROM Anagrafiche where DesScuola='"&SpScuola.SelectedItem&"' and Classe='"&SpClasse.SelectedItem&"' order by Sezione")
   For i = 0 To Cur.RowCount-1
     Cur.Position = i
         SpSezione.Add(Cur.GetString("Sezione"))
     Next
   Cur.Close
   SpSezione.SelectedIndex=0
End Sub

Sub SpSezione_ItemClick (Position As Int, Value As Object)
   'facciamo vedere gli alunni di questa classe e sezione
   bmpGrn.Initialize(File.DirAssets, "Circle_Green.png")
   bmpRed.Initialize(File.DirAssets, "Circle_Red.png")
   LstAlunni.Initialize("ListView1")
   LstAlunni.TwoLinesAndBitmap.ItemHeight = 55dip
  LstAlunni.TwoLinesAndBitmap.Label.TextSize = 15
   LstAlunni.TwoLinesAndBitmap.Label.TextColor = Colors.Black
   LstAlunni.FastScrollEnabled = True
   LstAlunni.Color = Colors.White
   LstAlunni.ScrollingBackgroundColor = Colors.White
   Activity.Color = Colors.White
   PopolaLista
End Sub

Sub PopolaLista
   LstAlunni.Clear
'   PnlDett.Visible = False
   Dim cur As Cursor
   cur = SQL1.ExecQuery("SELECT Studente, CogStudente, NomStudente, Bianco, Status, Note FROM Anagrafiche where DesScuola='"&SpScuola.SelectedItem&"' and Classe='"&SpClasse.SelectedItem&"' and Sezione='"&SpSezione.SelectedItem&"' order by CogStudente")
   For i = 0 To cur.RowCount-1
       cur.Position = i
     If cur.GetString("Status")="P" Then
       LstAlunni.AddTwoLinesAndBitmap(cur.GetString("Studente")&" "&cur.GetString("CogStudente")&" "&cur.GetString("NomStudente"),cur.GetString("Bianco")&" "&cur.GetString("Note"),bmpGrn)
     Else
       LstAlunni.AddTwoLinesAndBitmap(cur.GetString("Studente")&" "&cur.GetString("CogStudente")&" "&cur.GetString("NomStudente"),cur.GetString("Bianco")&" "&cur.GetString("Note"),bmpRed)
     End If   
   Next
   Activity.AddView(LstAlunni, 10, 320, 100%x, 75%y)
End Sub


Sub LstAlunni_ItemClick (Position As Int, Value As Object)
   Msgbox("ciao","")
End Sub
 

mc73

Well-Known Member
Licensed User
Longtime User
Why are you re-setting the listView here?
B4X:
Activity.AddView(LstAlunni, 10, 320, 100%x, 75%y)
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
Why are you re-setting the listView here?
B4X:
Activity.AddView(LstAlunni, 10, 320, 100%x, 75%y)

You're right mc73, I've moved the listview definition in activity_create, but the problem is still present!
I don't know what it could be, it's not the first listview that I use :-(

B4X:
#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: False
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

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 SQL1 As SQL        :SQL1 = Main.SQL1
   Private SpScuola As Spinner
   Private SpClasse As Spinner
   Private SpSezione As Spinner
   Private LstAlunni As ListView
   Dim bmpGrn As Bitmap
   Dim bmpRed As Bitmap
   Private LblAlunni As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("rilevazione")
   'devo riempire lo spinner scuole
   SpScuola.Add(" ")
   Dim Cur As Cursor
   Cur = SQL1.ExecQuery("SELECT distinct DesScuola FROM Anagrafiche order by Scuola")
   For i = 0 To Cur.RowCount-1
     Cur.Position = i
         SpScuola.Add(Cur.GetString("DesScuola"))
     Next
   Cur.Close
   SpScuola.SelectedIndex=0
   bmpGrn.Initialize(File.DirAssets, "Circle_Green.png")
   bmpRed.Initialize(File.DirAssets, "Circle_Red.png")
   LstAlunni.Initialize("ListView1")
   LstAlunni.TwoLinesAndBitmap.ItemHeight = 55dip
  LstAlunni.TwoLinesAndBitmap.Label.TextSize = 15
   LstAlunni.TwoLinesAndBitmap.Label.TextColor = Colors.Black
   LstAlunni.FastScrollEnabled = True
   LstAlunni.Color = Colors.White
   LstAlunni.ScrollingBackgroundColor = Colors.White
   Activity.Color = Colors.White
   Activity.AddView(LstAlunni, 10, 520, 100%x, 75%y)
   LblAlunni.Visible = False
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SpScuola_ItemClick (Position As Int, Value As Object)
   'devo riempire lo spinner classi
   SpClasse.Clear
   SpSezione.Clear
   LstAlunni.Clear
   SpClasse.Add(" ")
   Dim Cur As Cursor
   Cur = SQL1.ExecQuery("SELECT distinct Classe FROM Anagrafiche where DesScuola='"&SpScuola.SelectedItem&"' order by Classe")
   For i = 0 To Cur.RowCount-1
     Cur.Position = i
         SpClasse.Add(Cur.GetString("Classe"))
     Next
   Cur.Close
   SpClasse.SelectedIndex=0
End Sub

Sub SpClasse_ItemClick (Position As Int, Value As Object)
   'devo riempire lo spinner sezioni
   SpSezione.Clear
   LstAlunni.Clear
   SpSezione.Add(" ")
   Dim Cur As Cursor
   Cur = SQL1.ExecQuery("SELECT distinct Sezione FROM Anagrafiche where DesScuola='"&SpScuola.SelectedItem&"' and Classe='"&SpClasse.SelectedItem&"' order by Sezione")
   For i = 0 To Cur.RowCount-1
     Cur.Position = i
         SpSezione.Add(Cur.GetString("Sezione"))
     Next
   Cur.Close
   SpSezione.SelectedIndex=0
End Sub

Sub SpSezione_ItemClick (Position As Int, Value As Object)
   'facciamo vedere gli alunni di questa classe e sezione
   PopolaLista
End Sub

Sub PopolaLista
   LstAlunni.Clear
   Dim cur As Cursor
   cur = SQL1.ExecQuery("SELECT Studente, CogStudente, NomStudente, Dieta, Bianco, Status, Note FROM Anagrafiche where DesScuola='"&SpScuola.SelectedItem&"' and Classe='"&SpClasse.SelectedItem&"' and Sezione='"&SpSezione.SelectedItem&"' order by CogStudente")
   For i = 0 To cur.RowCount-1
       cur.Position = i
     If cur.GetString("Status")="P" Then
       LstAlunni.AddTwoLinesAndBitmap2(cur.GetString("CogStudente")&" "&cur.GetString("NomStudente"),"Dieta: "&cur.GetString("Dieta")&" "&"Bianco: "&cur.GetString("Bianco")&" "&"Note: "&cur.GetString("Note"),bmpGrn,cur.GetString("Studente"))
'       .AddTwoLinesAndBitmap(cur.GetString("Studente")&" "&cur.GetString("CogStudente")&" "&cur.GetString("NomStudente"),cur.GetString("Bianco")&" "&cur.GetString("Note"),bmpGrn)
     Else
       LstAlunni.AddTwoLinesAndBitmap2(cur.GetString("CogStudente")&" "&cur.GetString("NomStudente"),"Dieta: "&cur.GetString("Dieta")&" "&"Bianco: "&cur.GetString("Bianco")&" "&"Note: "&cur.GetString("Note"),bmpRed,cur.GetString("Studente"))
     '   LstAlunni.AddTwoLinesAndBitmap(cur.GetString("Studente")&" "&cur.GetString("CogStudente")&" "&cur.GetString("NomStudente"),cur.GetString("Bianco")&" "&cur.GetString("Note"),bmpRed)
     End If   
   Next
   LblAlunni.Visible = True
End Sub


Sub LstAlunni_ItemClick (Position As Int, Value As Object)
   Msgbox("ciao","")
End Sub

Sub LstAlunni_ItemLongClick (Position As Int, Value As Object)
   Activity.Finish
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I suppose that your ListView is defined with the Designer in a layout file.
If yes:
You must NOT initialize it in the code. Remove this line:
LstAlunni.Initialize("ListView1")

If it is not deined with the Designer
You must initialize it once and not in a click event and add it onto the Activity.
In your code this is wrong:
In your initialization you enter "ListView1" as the generic event name.
But you define Sub LstAlunni_ItemClick !?
So it should be LstAlunni.Initialize("LstAlunni").
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…