android.R.layout.simple_list_item_1, cityList));
}
public List
final List
try {
String
xmlStr
WebServiceCaller.doCallWebService(Constant.SOAP_ACTION, Constant.METHOD_NAME, map);
RootElement root = new RootElement(\ Element entry = root.getChild(\
entry.getChild(\ new EndTextElementListener() { public void end(String body) {
System.out.println(\ cityList.add(body); } });
create the factory
SAXParserFactory factory = SAXParserFactory.newInstance(); create a parser
SAXParser parser = factory.newSAXParser();
XMLReader xmlreader = parser.getXMLReader();
=
xmlreader.setContentHandler(root.getContentHandler());
get our data via the xml string
InputSource is = new InputSource(new StringBufferInputStream(xmlStr));
xmlreader.parse(is);
((TextView)findViewById(R.id.testText)).setText(result.toString()); } catch(Exception e) { e.printStackTrace();
((TextView)findViewById(R.id.testText)).setText(\
e.getClass().getName() + \ ((TextView)findViewById(R.id.lblStatus)).setText(E.getMessage());
return null;
}
return cityList; } @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
cityName = (String) l.getItemAtPosition(position);
callWeatherResultActivity(cityName);
super.onListItemClick(l, v, position, id);
}
+
private void callWeatherResultActivity(String cityName){
Log.d(\
Intent i = new Intent(getApplicationContext(), WeatherResult.class); i.putExtra(\ i.putExtra(\ i.putExtra(\
}
startActivity(i);
}
5.3.2 棨ϸ棩
package com.xmobileapp.android.weatherforecast;
import java.io.StringBufferInputStream; import java.util.HashMap; import java.util.Map;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource; import org.xml.sax.XMLReader;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.sax.Element;
import android.sax.EndTextElementListener; import android.sax.RootElement; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.TextView;
import com.xmobileapp.android.weatherforecast.meta.CityWeather; import com.xmobileapp.android.weatherforecast.meta.Constant;
import com.xmobileapp.android.weatherforecast.transport.WebServiceCaller;
public class WeatherResult extends Activity {
private CityWeather cityWeather;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.result);
TextView tv = (TextView) this.findViewById(R.id.resultText);
cityWeather = new CityWeather(); final StringBuffer sb = new StringBuffer();
Intent queryIntent = getIntent();
String cityName = queryIntent.getStringExtra(\String countryName = queryIntent.getStringExtra(\
Map map = new HashMap();