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
| package fr.emergenceit.quiz;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class ContentStats extends ListActivity {
String idClient;
DBAdapter db = new DBAdapter(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stats1);
// On récupère notre intent
String titre = getIntent().getStringExtra("valeur");
String modeJeu = getIntent().getStringExtra("modejeu");
// On affiche cette chaîne dans le textview
TextView textView = (TextView) findViewById(R.id.monTextView);
textView.setText(titre);
db.open();
Cursor getIdClient = db.dernierClient();
getIdClient.moveToFirst();
idClient = getIdClient.getString(0);
db.close();
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
JSONObject json = DBServer.getJSONfromURL("URL/getStats.php?idClient="+idClient+"&modeJeu="+modeJeu); //j'ai mis URL pour des raisons de sécurité
try{
Log.i("Liste Stats", "On essaye");
JSONArray stats = json.getJSONArray("stats");
for(int i=0;i<stats.length();i++){
Log.i("Liste Stats", ""+i);
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = stats.getJSONObject(i);
map.put("_id", ""+e.getString("_id"));
map.put("titrePack", "" + e.getString("titrePacks"));
map.put("dateStats", "" + e.getString("dateStats"));
map.put("points", "" + e.getString("points"));
mylist.add(map);
}
}
catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
final ListAdapter adapter = new SimpleAdapter(
this,
mylist,
R.layout.liststats,
new String[] { "titrePack", "dateStats", "points" },
new int[] { R.id.titrePack, R.id.dateStats, R.id.points });
setListAdapter(adapter);
}
} |
Partager