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
| public class Messages extends ListActivity {
private static final String MY_PREFERENCES = "mespreferences";
TextView txt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_enregist);
SharedPreferences sharedPreferences = getSharedPreferences(MY_PREFERENCES, 0);
String idcdt = sharedPreferences.getString("id", "");
ArrayList<NameValuePair> post_idsociete = new ArrayList<NameValuePair>();
post_idsociete.add(new BasicNameValuePair("id", idcdt));
ArrayList<HashMap<String, Object>> mylist = new ArrayList<HashMap<String, Object>>();
JSONObject json = JSONfunctions.getJSONUrlParam("http://10.0.2.2/mesRequetes/mesmessages.php",post_idsociete);
try{
if (json != null)
{
JSONArray offres_e = json.getJSONArray("messages");
for(int i=0;i<offres_e.length();i++)
try {
{
HashMap<String, Object> map = new HashMap<String, Object>();
JSONObject o = offres_e.getJSONObject(i);
map.put("message", "message:" + o.getString("message"));
map.put("first_name","société:"+ o.getString("first_name"));
map.put("idsoc",o.getString("idsoc"));
map.put("idrep",o.getString("idrep"));
map.put("idoff",o.getString("idoff"));
map.put("logo", "" + o.getString("logo"));
URL aURL = new URL("http://10.0.2.2"+ o.getString("logo"));
Bitmap bitmap = BitmapFactory.decodeStream(aURL.openStream());
map.put("logo",bitmap);
mylist.add(map);
Log.i("log_tag","message:"+o.getString("message")+
", Société:"+o.getString("first_name")+
", num msg: "+o.getString("idrep")+
", id société: "+o.getString("idsoc")+
", id de l'offre: "+o.getString("idoff")+
", logo: "+o.getString("logo")
);
}
}
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();
}
}
else
{
AlertDialog.Builder adb = new AlertDialog.Builder(Messages.this);
adb.setIcon(R.drawable.exclamation1);
adb.setTitle("Aucun message");
adb.setMessage("Vous n'avez aucun message");
adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
adb.show();
}
}
catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.list_msgs,
new String[] { "first_name", "message", "logo", "idsoc", "idrep" },
new int[] { R.id.TV_societe, R.id.TV_msg, R.id.logosoc });
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 intent_msg = new Intent(Messages.this, DetailMsg.class);
intent_msg.putExtra("idrep", o.get("idrep"));
intent_msg.putExtra("idsoc", o.get("idsoc"));
intent_msg.putExtra("idoff", o.get("idoff"));
startActivity(intent_msg);
}
});
}
} |
Partager