Bonjour à tous !
J'ai un petit problème par rapport à l'affichage des métadonnées du JSON suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 { "entreprise":{ "id":"4", "name":"Entreprise 4", "company":"GOOGLE", "city":"adad", "registering_date":"inscrit le 10/12/2014", "number_of_employee":"12000", "category":"Technologie", "url":"http://google.fr", "sa":"15 000 000 ", "metas":{ "meta":[ { "description":"Google Inc. est une société fondée le 4 septembre 1998 dans le garage Google dans la Silicon Valley, en Californie, par Larry Page et Sergueï Brin, créateurs du moteur de recherche Google. L'entreprise s'est principalement fait connaître à travers la situation monopolistique de son moteur de recherche, concurrencé historiquement par AltaVista puis par Yahoo! et Bing. Elle a ensuite procédé à de nombreuses acquisitions et développements et détient aujourd'hui de nombreux logiciels et sites web notables parmi lesquels YouTube, le système d'exploitation pour téléphones mobiles Android, Google Earth, Google Maps et bien d'autres. Google s'est donné comme mission « d'organiser l'information à l'échelle mondiale et de la rendre universellement accessible et utile »" }, { "annonces":[ { "id":"1", "title":"GOOGLE - DÉVELOPPEUR", "avatar":"http://myc2v.com:8080/static/img/jobs/00003/normal_size.png", "description":"Les ingénieurs logiciel de Google développent les nouvelles technologies qui changent la manière dont plusieurs millions d'utilisateurs communiquent, explorent et interagissent avec les informations. Nos ambitions dépassent largement la seule recherche Google. Nos produits doivent pouvoir gérer les", "contract":"CDI", "category":"INFORMATIQUE", "city":"ADAD" }, { "id":"2", "title":"GOOGLE - DÉVELOPPEUR", "avatar":"http://myc2v.com:8080/static/img/jobs/00003/normal_size.png", "description":"Lancer, retravailler et faire la différence : apporter votre expertise en matière de codage d'interface, et être déterminé à créer des expériences extraordinaires pour nos utilisateurs Concevoir des applications Web nouvelle génération orientées client Créer des interfaces Web aux performances ha", "contract":"CDI", "category":"INFORMATIQUE", "city":"ADAD" } ] } ] } } }
Mon problème principal survient lors de l'instanciation suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part ListAdapter adapter2 = new SimpleAdapter(SingleItemActivity.this, metasList, R.layout.list_metas, new String[]{TAG_DESCRIPTION, TAG_TITLE, TAG_AVATAR, TAG_DESCRIPTIONA, TAG_CONTRACT, TAG_CATEGORY, TAG_CITY}, new int[]{R.id.description2, R.id.title, R.id.avatar, R.id.description3, R.id.contract, R.id.category2, R.id.city3});
En effet, si le JSON présenté possède deux annonces différentes, pour d'autres entreprises il n'y en aura qu'une seule, et pour d'autres trois.
Voici le code de l'activité responsable de l'affichage de ces données :
L'instruction jParse.execute() renverra à la méthode parsingComplete() une fois le parsing terminé.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175 package com.aziz.bdk.applimvcv2; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; public class SingleItemActivity extends Activity implements ParsingListener{ private static final String urldescentreprises = "http://91.121.26.112/lucas/jsongoogledetail.txt"; private static final String TAG_DESCRIPTION = "description"; private static final String TAG_ID = "id"; private static final String TAG_TITLE = "title"; private static final String TAG_AVATAR = "avatar"; private static final String TAG_DESCRIPTIONA = "descriptionA"; private static final String TAG_CONTRACT = "contract"; private static final String TAG_CATEGORY = "category"; private static final String TAG_CITY = "city"; private TextView companyTV; private TextView cityTV; private TextView registering_dateTV; private TextView number_of_employeeTV; private TextView categoryTV; private TextView urlTV; private TextView saTV; private ListView lv; private JParse jParse; private String numid; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.singleactivity_main); Intent in = getIntent(); numid = in.getStringExtra(TAG_ID); jParse = new JParse(urldescentreprises, this); jParse.execute(); } public void parsingComplete() { Entreprise entreprise = Entreprise.getEntreprise(jParse); companyTV = (TextView) findViewById(R.id.company2); companyTV.setText(entreprise.getCompany()); cityTV = (TextView) findViewById(R.id.city2); cityTV.setText(entreprise.getCity()); registering_dateTV = (TextView) findViewById(R.id.registering_date); registering_dateTV.setText(entreprise.getRegistering_date()); number_of_employeeTV = (TextView) findViewById(R.id.number_of_employee); number_of_employeeTV.setText(entreprise.getNumber_of_employee()); categoryTV = (TextView) findViewById(R.id.category); categoryTV.setText(entreprise.getCategory()); urlTV = (TextView) findViewById(R.id.url); urlTV.setText(entreprise.getUrl()); saTV = (TextView) findViewById(R.id.sa); saTV.setText(entreprise.getSa()); String description = entreprise.getDescription(); String idA = entreprise.getIdA(); String title = entreprise.getTitle(); String avatar = entreprise.getAvatar(); String descriptionA = entreprise.getDescriptionA(); String contract = entreprise.getContract(); String categoryA = entreprise.getCategoryA(); String cityA = entreprise.getCityA(); lv = (ListView) findViewById(R.id.metaslv); ArrayList<HashMap<String, String>> metasList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map = new HashMap<String, String>(); map.put(TAG_DESCRIPTION, description); map.put(TAG_ID, idA); map.put(TAG_TITLE, title); map.put(TAG_AVATAR, avatar); map.put(TAG_DESCRIPTIONA, descriptionA); map.put(TAG_CONTRACT, contract); map.put(TAG_CATEGORY, categoryA); map.put(TAG_CITY, cityA); metasList.add(map); if(entreprise.getIdA2()!=null) { String idA2 = entreprise.getIdA2(); String title2 = entreprise.getTitle2(); String avatar2 = entreprise.getAvatar2(); String descriptionA2 = entreprise.getDescriptionA2(); String contract2 = entreprise.getContract2(); String categoryA2 = entreprise.getCategoryA2(); String cityA2 = entreprise.getCityA2(); HashMap<String, String> map2 = new HashMap<String, String>(); map2.put(TAG_ID, idA2); map2.put(TAG_TITLE, title2); map2.put(TAG_AVATAR, avatar2); map2.put(TAG_DESCRIPTIONA, descriptionA2); map2.put(TAG_CONTRACT, contract2); map2.put(TAG_CATEGORY, categoryA2); map2.put(TAG_CITY, cityA2); metasList.add(map); if(entreprise.getIdA3()!=null) { String idA3 = entreprise.getIdA3(); String title3 = entreprise.getTitle3(); String avatar3 = entreprise.getAvatar3(); String descriptionA3 = entreprise.getDescriptionA3(); String contract3 = entreprise.getContract3(); String categoryA3 = entreprise.getCategoryA3(); String cityA3 = entreprise.getCityA3(); HashMap<String, String> map3 = new HashMap<String, String>(); map3.put(TAG_ID, idA3); map3.put(TAG_TITLE, title3); map3.put(TAG_AVATAR, avatar3); map3.put(TAG_DESCRIPTIONA, descriptionA3); map3.put(TAG_CONTRACT, contract3); map3.put(TAG_CATEGORY, categoryA3); map3.put(TAG_CITY, cityA3); metasList.add(map); } } ListAdapter adapter2 = new SimpleAdapter(SingleItemActivity.this, metasList, R.layout.list_metas, new String[]{TAG_DESCRIPTION, TAG_TITLE, TAG_AVATAR, TAG_DESCRIPTIONA, TAG_CONTRACT, TAG_CATEGORY, TAG_CITY}, new int[]{R.id.description2, R.id.title, R.id.avatar, R.id.description3, R.id.contract, R.id.category2, R.id.city3}); lv.setAdapter(adapter2); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { HashMap<String, String> map = (HashMap<String, String>) parent.getItemAtPosition(position); JSONObject selectedObject = new JSONObject(map); try { String identifiant = selectedObject.getString(TAG_ID); Intent in = new Intent(getApplicationContext(), AnnonceDetailsActivity.class); in.putExtra(TAG_ID, identifiant); startActivity(in); } catch (JSONException e) { e.printStackTrace(); } } }); } }
Il y aura toujours au minimum une annonce, et au maximum trois.
EDIT : Le problème actuel est qu'une seule annonce est affichée, et ce trois fois (la même annonce), et la description générale de l'entreprise, que je ne souhaiterai qu'afficher une fois avant la première annonce est affichée trois fois également.
L'affichage et les données de chaque annonce seront toujours les mêmes, cependant j'ai une petite question : comme la description (TAG_DESCRIPTION) de l'entreprise fait partie de l'ArrayList, comment gérer le fait qu'elle ne soit affichée qu'une fois, avant la première annonce ?
Voici mon fichier R.layout.list_metas :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/description2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#acacac" android:paddingBottom="2dip" android:paddingLeft="5dip" > </TextView> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#acacac" android:paddingBottom="2dip" android:paddingLeft="5dip" > </TextView> <TextView android:id="@+id/avatar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#acacac" android:paddingBottom="2dip" android:paddingLeft="5dip" > </TextView> <TextView android:id="@+id/description3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#acacac" android:paddingBottom="2dip" android:paddingLeft="5dip"> </TextView> <TextView android:id="@+id/contract" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#acacac" android:paddingBottom="2dip" android:paddingLeft="5dip"> </TextView> <TextView android:id="@+id/category2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#acacac" android:paddingBottom="2dip" android:paddingLeft="5dip"> </TextView> <TextView android:id="@+id/city3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#acacac" android:paddingBottom="2dip" android:paddingLeft="5dip"> </TextView> </LinearLayout>
Merci d'avance pour votre aide !![]()
Partager