How to retrive elements from a ListView

ciginfo

Well-Known Member
Licensed User
Longtime User
Hi,
I load records from a server into a ListView (ListViewAffiche)
I want retrieve some elements (nom, text )of a record when I click on one line of the ListView (Sub ListViewAffiche_ItemClick) to put them in a label in another activity. How to do, what code in Sub ListViewAffiche_ItemClick
Have I to use an array? How?
I don' know if you understand well because my bad english.
Thank you

Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("http://ciginfo.alwaysdata.net/connection.php", Query)
End Sub
Sub ExtraitListeAffiche
ProgressDialogShow("Extrait les données")

ExecuteRemoteQuery("SELECT id, nom, adresse, telephone, mail, longitude, latitude, ville, departement, what, texte, url, url_image, ce_moment FROM kinderbreak WHERE ce_moment = 1 ORDER BY id", AFFICHE_LIST)

End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim RES As String
RES = Job.GetString
Log("Response from server: " & RES)
Dim parser As JSONParser
parser.Initialize(RES)
Select Job.JobName

Case AFFICHE_LIST
Dim AFFICHE As List
AFFICHE = parser.NextArray 'returns a list with maps
For i = 0 To AFFICHE.Size - 1
Dim M As Map
M = AFFICHE.Get(i)
Dim Nom, Adresse, Telephone, Mail, Ville, Texte, URL, URL_Image As String
Dim Index,Departement, What, Ce_moment As Int
Dim Longitude, Latitude As Double
Index = M.Get("id")
Nom = M.Get("nom")
Adresse = M.Get("adresse")
Ville = M.Get("ville")
Departement = M.Get("departement")
Longitude = M.Get("longitude")
Latitude = M.Get("latitude")
Telephone = M.Get("telephone")
Mail = M.Get("mail")
What = M.Get("what")
Texte = M.Get("texte")
URL = M.Get("url")
URL_Image = M.Get("url_image")
Ce_moment = M.Get("ce_moment")

ListViewAffiche.AddTwoLines(Nom, Adresse & ", " & Ville & " " & Departement & ". Tel: " & Telephone)
Next
Sub ListViewAffiche_ItemClick (Position As Int, Value As Object)

'What I have to code here??????????????????

End Sub
 

klaus

Expert
Licensed User
Longtime User
I would suggest you to use this to fill the ListView:
Je te suggère d'utiliser cette ligne pour remplir la ListView:
B4X:
ListViewAffiche.AddTwoLines2(Nom, Adresse & ", " & Ville & " " & Departement & ". Tel: " & Telephone, M)
In Process_Globals :
Dans Process_Globals :
B4X:
Process_Globals
    Dim mapData as Map
Then in ListViewAffiche_ItemClick:
Puis, dans ListViewAffiche_ItemClick:
B4X:
Sub ListViewAffiche_ItemClick (Position As Int, Value As Object)
     mapData = Value
End Sub
In mapData you have the whole selected record.
And mapData can be accessed from any module with Main.mapData.

mapData contient l'enregistrement sélectionné complet.
Et mapData est accessible deuis n'importe quel module avec Main.mapData.

Best regards.
Meilleures salutations.
 
Last edited:
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Thank you klaus and in french.
But if I want only one element when I Item_Click, for example only "Nom" or only " telephone", how to do?
Thank you

PS, Where can I find a tuto about "Map" and Mapdata?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
With AddTwoLines2 you define the return object.
You could do it for nom:
B4X:
ListViewAffiche.AddTwoLines2(Nom, Adresse & ", " & Ville & " " & Departement & ". Tel: " & Telephone, Nom)
and in
B4X:
Sub ListViewAffiche_ItemClick (Position As Int, Value As Object)
     Nom = Value
End Sub
or similar for Telephone with
B4X:
ListViewAffiche.AddTwoLines2(Nom, Adresse & ", " & Ville  & " " & Departement & ". Tel: " & Telephone, Telephone)
or for
B4X:
ListViewAffiche.AddTwoLines2(Nom, Adresse & ", " & Ville & " " & Departement & ". Tel: " & Telephone, M)
and in
B4X:
Sub ListViewAffiche_ItemClick (Position As Int, Value As Object)
    mapData = Value
    Nom = mapData.Get("nom")
    Telephone = mapData.Get("telephone")
End Sub
There si no specific tutorial about Map objects but you find the help here.
mapData is only the name I gave for the Map object in the example.
 
Upvote 0
Top