import androsd.widoet.Tonst import java.io.Inputstreams
8
9impont java.ut11.Arrayliati10 inport java.uti1.RashMap;1n import java.otll.listy
V3ew.OnClicklistener
121mport Java.ut11.Map; 13 publio class MainActinaty extends AppCompatActivity Impiements
14
15 private textview tvcitys
16 private Textview tvweathes
17 private Textview tvtemp;
18 private Textview tywindi
19 private Textview tvpm:
20 private Imageview ivicons
21 private Map<string,Stcing> map;
22 private ListkMap<string,String>> listi
23 private steing temp. weathet, name, pm, windy
24 @Override
25 protected vola oncreate Bundle savedinstancestatel(
26 super.onCreate(savedInstancestatel;
27 setcontentview(R.layout.activity main)7
28 //初始化文本控件
29 inieView():
30 try
31 //读取 weather1.xm1 文件
Enputstream is- this.getResouoes 0 .openRawResource (R.raw .weather1):
32
33 //把每个城市的天气信息集合存到weatherInfos中
List weatherInfos- Weatherservice.getInfosFromXML(is);
3y
35 /循环读取 weatherinfos 中的每一条数据
36 list n new ArrayList<Map<String,String>>()i
forWeatherinfo info: weatherInfos) t
37
38 map new HashMap<String,String>():
39 map.put(“temp”,info.getTemp 0));
40 map.put(“weather”,info.getWeather()):
43 map.puc(#name",info.getName ))))
42 map.out(“pm”,info.getEm0)7
43 map-put(wind",info.getwind0);
liat.add(map);
45
46 icateh (Excaption eli
47 eprintstacktracel):
48 Toast.makeTest(this,“解析信息失败”,Toast.LENGTH.SHORT).show01
49
50 //自定义 gecMap 0方法,显示天气信息到文本控件中,默认显示北京的天气
51 getMap(,3.dtawable.aun):
32
53 private vold initview0I
54 tecityTextvieFindviewByiaiR.id.tveaty):
55
thwenthor Textvlew tindvtewByndta.sd.t.wenthecis