Problème d'affichage de données
Salut, je développe une application qui permet d'afficher des données de ma base de donnée en JSON. j'arrive à récupérer les informations et je les affiche dans le log mais les informations ne s'affichent pas dans mon activity, je ne sais vraiment pas où se trouve l'erreur. Aidez moi svp car c'est urgent.
Voici comment je procède
Code:
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
| protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_all_news, "GET", params);
// voir la reponse dans le log cat
Log.d("Toutes les infos: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// info found
// Getting Array of informations
information = json.getJSONArray(TAG_ID);
// looping through All Products
for (int i = 0; i < information.length(); i++) {
JSONObject c = information.getJSONObject(i);
// Storing each json item in variable
String titre = c.getString(TAG_ID);
String desc = c.getString(TAG_TITRE);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_ID, titre);
map.put(TAG_TITRE, desc);
// adding HashList to ArrayList
InfosList.add(map);
}
} else {
// no informations found
// Launch empty Activity
Intent i = new Intent(getApplicationContext(),
nouveau.class);
//Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url){
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, InfosList,
R.layout.activity_main, new String[] {TAG_ID,TAG_TITRE},
new int[] {R.id.idInfo,R.id.txtInfo});
setListAdapter(adapter);
}
});
}
} |