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
| public class Consultationmsgmembre extends ListActivity{
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> Listemessage;
private static String url_lalistemessagemembre = "http://10.0.2.2/projet2/consultemessagemembre.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_message = "message";
private static final String TAG_IDM = "id_membre";
private static final String TAG_idmsgmembre = "id_message";
private static final String TAG_objet = "objet";
private static final String TAG_cont= "contenu";
private static final String TAG_datemsg = "date_message";
private static final String TAG_IDG = "id_groupe";
JSONArray message = null;
String id_membre;
String id_groupe;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listemessagemembre);
Intent in = getIntent();
id_membre = in.getStringExtra(TAG_IDM );
id_groupe = in.getStringExtra(TAG_IDG );
Listemessage = new ArrayList<HashMap<String, String>>();
new Telechargermessages().execute();
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String id_message = ((TextView) view.findViewById(R.id.idmsgmembree)).getText()
.toString();
Intent in = new Intent(getApplicationContext(), Detailemessagemembre.class);
in.putExtra(TAG_idmsgmembre, id_message);
startActivity(in);
}
});
}
class Telechargermessages extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Consultationmsgmembre.this);
pDialog.setMessage("chargement des messages...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id_membre", id_membre));
//params.add(new BasicNameValuePair("id_groupe", id_groupe));
JSONObject json = jParser.makeHttpRequest(url_lalistemessagemembre, "GET", params);
Log.d("tout les messages : ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
message = json.getJSONArray(TAG_message);
for (int i = 0; i < message.length(); i++) {
JSONObject c = message.getJSONObject(i);
String id_message = c.getString(TAG_idmsgmembre);
String objet = c.getString(TAG_objet);
String date_message = c.getString(TAG_datemsg);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_idmsgmembre, id_message);
map.put(TAG_objet, objet);
map.put(TAG_datemsg, date_message);
Listemessage.add(map);
}
} else {
Toast.makeText(Consultationmsgmembre.this, "la liste des messages est vide ", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
Consultationmsgmembre.this, Listemessage,
R.layout.messagemembreitems, new String[] {
TAG_idmsgmembre, TAG_objet, TAG_datemsg },
new int[] {R.id.idmsgmembree, R.id.objetmsgmembree, R.id.datemsgmembree });
setListAdapter(adapter);
}
});
}
}
} |
Partager