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
| package com.my.package;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class Announces extends Activity{
Context context;
private static final String SOAP_ACTION = "getData";
private static final String OPERATION_NAME = "getData";
private static final String WSDL_TARGET_NAMESPACE = "http://www.monsite.com/webservice/";
private static final String SOAP_ADDRESS = "http://www.monsite.com/webservice/soapserver.php";
public final static String ITEM_TITLE = "title";
public final static String ITEM_PHOTO = "photo";
public final static String ITEM_DESCRIPTION = "description";
public Map<String,?> createItem(String photo, String title, String description) {
Map<String,String> item = new HashMap<String,String>();
item.put(ITEM_PHOTO, photo);
item.put(ITEM_TITLE, title);
item.put(ITEM_DESCRIPTION, description);
return item;
}
private ListView lvListe;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.announces);
context = this;
lvListe = (ListView) findViewById(R.id.ListAnnounces);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
ArrayList<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
try{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
String jString = response.toString();
try {
JSONArray jsonArray = new JSONArray(jString);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String AttrMarque = jsonObject.getString("marque");
String AttrReference = jsonObject.getString("reference");
String AttrResume = jsonObject.getString("resume");
String AttrTitle = AttrMarque+" "+AttrReference;
map = new HashMap<String, String>();
map.put(ITEM_PHOTO, "http://ondrejcermak.info/wp-content/uploads/2010/11/Android_logo.svg_.png");
map.put(ITEM_TITLE, AttrTitle);
map.put(ITEM_DESCRIPTION, AttrResume);
items.add(map);
}
}catch (JSONException e){
lvListe.setFilterText(e.toString());
}
}catch (Exception exception){
lvListe.setFilterText(exception.toString());
}
SimpleAdapter mSchedule = new SimpleAdapter (
this,
items,
R.layout.list_announces,
new String[] {ITEM_PHOTO, ITEM_TITLE, ITEM_DESCRIPTION},
new int[] {R.id.list_announces_photo, R.id.list_announces_title, R.id.list_announces_description}
);
lvListe.setAdapter(mSchedule);
lvListe.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent intent = new Intent(context, Announce.class);
context.startActivity(intent);
}
});
}
} |
Partager