Listview

sultan87

Active Member
Licensed User
Longtime User
Hello
Here 's my program

Sub Process_Globals

End Sub

Sub Globals
Dim List_Pays as ListView
Dim List_Regions as ListView
Dim List_Villes as ListView
Dim List_Affich as ListView
Dim Pays, Regions, Villes as Panel
Dim Name as String
End Sub

Sub Activity_Create(FirstTime As Boolean)

' Load List_Pays
' Load_List_Regions
' Load_List_Villes

Pays.Initialize("Pays")
Regions.Initialize("Regions")
Villes.Initialize("Villes")

End Sub

Sub Pays_Click
Name = "Pays"
Affich(Pays)
End Sub

Sub Regions_Click
Name = "Regions"
Affich(Regions)
End Sub

Sub Villes_Click
Name = "Villes"
Affich(Villes)
End Sub

Sub Affich(List as ListView)
List_Affich.Initialize("ListClick")
List_Affich = List
Msgbox("List_size " & List.Size,"Suivi")
Msgbox("List_Affich_size " & List_Affich.Size,"Suivi")
Activity.AddView(List_Affich,0,20,100,180)
End Sub

Sub ListClick_ItemClick(Position As Int, Value As Object)
Select Case name
Case "Pays"
Pays.Text = List_Affich.GetItem(position)
Case "Regions"
Regions.Text = List_Affich.GetItem(position)
Case "Villes"
Villes.Text = List_Affich.GetItem(position)
End Select
End Sub

if I click on Pays the first time not problem

if I click again on Pays problem

List.size = 0
List_Affich.size = 0


Why ???

Best regards
 

thedesolatesoul

Expert
Licensed User
Longtime User
The problem is in this sub:
B4X:
Sub Affich(List as ListView)
List_Affich.Initialize("ListClick")
List_Affich = List
Msgbox("List_size " & List.Size,"Suivi")
Msgbox("List_Affich_size " & List_Affich.Size,"Suivi")
Activity.AddView(List_Affich,0,20,100,180)
End Sub
When you click the first time, List_Affich is initialized and is assigned to List.
This is an assignment by reference, so this means that any operations on List_Affich will affect List as well (since they are now they same object).
When you click Pays again, List_Affich is initialized again, so List is initialized again so List_Pays is initialized again and is therefore empty.

Also, I think there is another error. You are passing Pays to the sub, not List_Pays, so you are passing the panel instead of the listview.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…