我想ListView
从一个ArrayList
.
ArrayList
填充了正确的值。在模拟器上,我得到的是具有值的列表项
包名 ClassName@someNumber
有人有同样的问题吗??
public class ExchangeMoneyMKActivity extends Activity {
Document dom;
private static final String METHOD_NAME = "GetExchangeRate";
private static final String NAMESPACE = "http://www.nbrm.mk/klservice/";
private static final String SOAP_ACTION=NAMESPACE+METHOD_NAME;
private static final String URL = "http://www.nbrm.mk/klservice/kurs.asmx?kurs";
ListView lw;
ArrayList<String>currencyShortNames=new ArrayList<String>();
ArrayList<String>currencyRates=new ArrayList<String>();
ArrayList<ExchangeRate> currencyList=new ArrayList<ExchangeRate>();
ArrayAdapter<ExchangeRate> aa;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
currencyShortNames.add("EUR");
currencyShortNames.add("USD");
currencyShortNames.add("GBP");
currencyShortNames.add("CHF");
currencyShortNames.add("SEK");
currencyShortNames.add("NOK");
currencyShortNames.add("JPY");
currencyShortNames.add("DKK");
currencyShortNames.add("CAD");
currencyShortNames.add("AUD");
lw=(ListView)this.findViewById(R.id.listView1);
aa = new ArrayAdapter<ExchangeRate>(
this,android.R.layout.simple_list_item_1,
currencyList);
lw.setAdapter(aa);
callService();
}
private void callService() {
try{
SoapObject request=new SoapObject(NAMESPACE,METHOD_NAME);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
java.util.Date date = new java.util.Date();
request.addProperty("StartDate",dateFormat.format(date));
request.addProperty("EndDate",dateFormat.format(date));
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//MyXmlParserHandler parser=new MyXmlParserHandler();
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
String resultData = result.toString();
// System.out.println(resultData);
int strStart=resultData.lastIndexOf("schema");
int strStop=resultData.lastIndexOf("dsKurs");
int strLength=strStop-strStart-10;
String responseXML=resultData.substring(strStart+10,strLength);
responseXML.replace("<", "<");
responseXML.replace(">", ">");
String xmlDocument="<?xml version=\"1.0\" encoding=\"utf-8\" ?>"+
"<dsKurs>" +
responseXML +
"</dsKurs>";
System.out.println(xmlDocument);
XMLfromString(resultData);
}catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void XMLfromString(String resultData) throws ParserConfigurationException, SAXException, IOException {
// TODO Auto-generated method stub
InputStream is = new ByteArrayInputStream(resultData.getBytes("UTF-8"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
try{
dom = db.parse(is);
}catch(Exception e){
System.out.println("Fatal error");
}
dom.getDocumentElement();
NodeList nl = dom.getElementsByTagName("KursZbir");
currencyList.clear();
if (nl != null && nl.getLength() > 0) {
for (int i = 0 ; i < nl.getLength(); i++) {
Element kursZbir = (Element)nl.item(i);
Element sreden = (Element)kursZbir.getElementsByTagName("Sreden").item(0);
currencyRates.add(sreden.getFirstChild().getNodeValue());
}
}
for(int i=0;i<currencyShortNames.size();i++){
currencyList.add(new ExchangeRate(currencyShortNames.get(i).toString(),currencyRates.get(i).toString()));
System.out.println(currencyList.get(i).shName.toString());
System.out.println(currencyList.get(i).Currency.toString());
aa.notifyDataSetChanged();
}
}
}