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
| ublic class Offres extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_offres);
ArrayList<HashMap<String, Object>> mylist = new ArrayList<HashMap<String, Object>>();
JSONObject json = JSONfunctions.getJSONfromURL("http://10.0.2.2/mesRequetes/test.php");
try{
JSONArray offres = json.getJSONArray("offres");
for(int i=0;i<offres.length();i++){
HashMap<String, Object> map = new HashMap<String, Object>();
JSONObject o = offres.getJSONObject(i);
map.put("poste", "Poste:" + o.getString("poste"));
map.put("first_name", "Société: " + o.getString("first_name"));
map.put("idoffre", o.getString("idoffre"));
//map.put("photo",bitmap);
map.put("photo", "" + o.getString("photo"));
URL aURL = new URL("http://10.0.2.2"+ o.getString("photo"));
Bitmap bitmap = BitmapFactory.decodeStream(aURL.openStream());
map.put("photo",bitmap);
mylist.add(map);
Log.i("log_tag","Poste:"+o.getString("poste")+
", Société:"+o.getString("first_name")+
", Numero de l'offre:"+o.getString("idoffre")+
", Logo de la société:"+o.getString("photo")
);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SimpleAdapter adapter = new SimpleAdapter(this, mylist , R.layout.accueil,
new String[] { "poste", "first_name", "idoffre", "photo" },
new int[] { R.id.TV_poste, R.id.TV_societe, R.id.logo });
adapter.setViewBinder(new MyViewBinder());
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Intent intent3 = new Intent(Offres.this, DetailsOffre.class);
intent3.putExtra("idoffre", o.get("idoffre"));
startActivity(intent3);
}
});
}
} |
Partager