#android天气预报源代码Word文件下载.docx
- 文档编号:22191744
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:28
- 大小:36.43KB
#android天气预报源代码Word文件下载.docx
《#android天气预报源代码Word文件下载.docx》由会员分享,可在线阅读,更多相关《#android天气预报源代码Word文件下载.docx(28页珍藏版)》请在冰豆网上搜索。
super.onCreate(savedInstanceState>
setContentView(R.layout.main1>
ETplace=(EditText>
findViewById(R.id.place>
query=(Button>
findViewById(R.id.query>
imView=(ImageView>
findViewById(R.id.myImageView>
placeName=(TextView>
findViewById(R.id.tvPlace>
query.setOnClickListener(newButton.OnClickListener(>
publicvoidonClick(Viewv>
try{
TvPlace=(TextView>
//Stringplace=ETplace.getText(>
.toString(>
Stringplace=
CntoSpell.getFullSpell(ETplace.getText(>
>
placeName.setText(place>
Stringweather="
"
//Stringurl="
//+place。
Stringurl="
DefaultHttpClientclient=newDefaultHttpClient(>
HttpUriRequestreq=newHttpGet(url>
HttpResponseresp=client.execute(req>
//StringstrResult=
//EntityUtils.toString(resp.getEntity(>
//Log.i("
weather->
strResult>
//一华氏度等于9/5摄氏度数值+32
HttpEntityent=resp.getEntity(>
InputStreamstream=ent.getContent(>
DocumentBuilderb=DocumentBuilderFactory.newInstance(>
.newDocumentBuilder(>
Documentd=b.parse(newInputSource(stream>
NodeListn=d.getElementsByTagName("
forecast_conditions"
//获得图片url当天的。
StringimgUrl="
imgUrl+=n.item(0>
.getChildNodes(>
.item(3>
.getAttributes(>
.item(0>
.getNodeValue(>
imView.setImageBitmap(Utils.returnBitMap(imgUrl>
//今后4天预报
for(inti=0。
i<
n.getLength(>
i++>
weather+=Utils.week(n.item(i>
.item(0>
.getAttributes(>
weather+="
"
weather+=(Integer
.parseInt(n.item(i>
.item(1>
.getAttributes(>
-32>
*5/9。
~"
.item(2>
weather+=Utils
.weather(n.item(i>
.item(4>
\n"
}
Log.i("
parseedweather->
weather>
TvPlace.setText(weather>
}catch(Exceptione>
e.printStackTrace(>
}
}
}>
}
}
Utils类:
importjava.io.IOException。
import.HttpURLConnection。
import.MalformedURLException。
import.URL。
importandroid.graphics.Bitmap。
importandroid.graphics.BitmapFactory。
publicclassUtils{
publicstaticStringweek(StringenWeek>
if(enWeek.equals("
Mon"
||enWeek.equals("
Monday"
return"
星期一"
elseif(enWeek.equals("
Tue"
Tuesday"
星期二"
Wed"
Wednesday"
星期三"
Thu"
Thursday"
星期四"
Fri"
Friday"
星期五"
Sat"
Saturday"
星期六"
Sun"
Sunday"
星期日"
publicstaticStringweather(StringenWeather>
if(enWeather.equals("
Clear"
晴"
elseif(enWeather.equals("
PartlySunny"
||enWeather.equals("
partly_cloudy"
多云"
ChanceofRain"
晴转雨"
storm"
暴雨"
thunderstorm"
雷阵雨"
fog"
大雾"
haze"
有雾"
rain"
雨"
heavyrain"
大雨"
lightrain"
小雨"
snow"
有雪"
///还需要补充。
publicstaticBitmapreturnBitMap(StringimgUrl>
URLmyImgUrl=null。
Bitmapbitmap=null。
myImgUrl=newURL(imgUrl>
}catch(MalformedURLExceptione>
e.printStackTrace(>
}
HttpURLConnectionconn=(HttpURLConnection>
myImgUrl
.openConnection(>
conn.setDoInput(true>
conn.connect(>
InputStreamis=conn.getInputStream(>
bitmap=BitmapFactory.decodeStream(is>
is.close(>
}catch(IOExceptione>
returnbitmap。
CntoSpell类:
importjava.util.Iterator。
importjava.util.LinkedHashMap。
importjava.util.Set。
publicclassCntoSpell{
privatestaticLinkedHashMapspellMap=null。
static{
if(spellMap==null>
spellMap=newLinkedHashMap(400>
initialize(>
//System.out.println("
ChinesetransferSpellDone."
privateCntoSpell(>
privatestaticvoidspellPut(Stringspell,intascii>
spellMap.put(spell,newInteger(ascii>
privatestaticvoidinitialize(>
spellPut("
a"
-20319>
ai"
-20317>
an"
-20304>
ang"
-20295>
ao"
-20292>
ba"
-20283>
bai"
-20265>
ban"
-20257>
bang"
-20242>
bao"
-20230>
bei"
-20051>
ben"
-20036>
beng"
-20032>
bi"
-20026>
bian"
-20002>
biao"
-19990>
bie"
-19986>
bin"
-19982>
bing"
-19976>
bo"
-19805>
bu"
-19784>
ca"
-19775>
cai"
-19774>
can"
-19763>
cang"
-19756>
cao"
-19751>
ce"
-19746>
ceng"
-19741>
cha"
-19739>
chai"
-19728>
chan"
-19725>
chang"
-19715>
chao"
-19540>
che"
-19531>
chen"
-19525>
cheng"
-19515>
chi"
-19500>
chong"
-19484>
chou"
-19479>
chu"
-19467>
chuai"
-19289>
chuan"
-19288>
chuang"
-19281>
chui"
-19275>
chun"
-19270>
chuo"
-19263>
ci"
-19261>
cong"
-19249>
cou"
-19243>
cu"
-19242>
cuan"
-19238>
cui"
-19235>
cun"
-19227>
cuo"
-19224>
da"
-19218>
dai"
-19212>
dan"
-19038>
dang"
-19023>
dao"
-19018>
de"
-19006>
deng"
-19003>
di"
-18996>
dian"
-18977>
diao"
-18961>
die"
-18952>
ding"
-18783>
diu"
-18774>
dong"
-18773>
dou"
-18763>
du"
-18756>
duan"
-18741>
dui"
-18735>
dun"
-18731>
duo"
-18722>
e"
-18710>
en"
-18697>
er"
-18696>
fa"
-18526>
fan"
-18518>
fang"
-18501>
fei"
-18490>
fen"
-18478>
feng"
-18463>
fo"
-18448>
fou"
-18447>
fu"
-18446>
ga"
-18239>
gai"
-18237>
gan"
-18231>
gang"
-18220>
gao"
-18211>
ge"
-18201>
gei"
-18184>
gen"
-18183>
geng"
-18181>
gong"
-18012>
gou"
-17997>
gu"
-17988>
gua"
-17970>
guai"
-17964>
guan"
-17961>
guang"
-17950>
gui"
-17947>
gun"
-17931>
guo"
-17928>
ha"
-17922>
hai"
-17759>
han"
-17752>
hang"
-17733>
hao"
-17730>
he"
-17721>
hei"
-17703>
hen"
-17701>
heng"
-17697>
hong"
-17692>
hou"
-17683>
hu"
-17676>
hua"
-17496>
huai"
-17487>
huan"
-17482>
huang"
-17468>
hui"
-17454>
hun"
-17433>
huo"
-17427>
ji"
-17417>
jia"
-17202>
jian"
-17185>
jiang"
-16983>
jiao"
-16970>
jie"
-16942>
jin"
-16915>
jing"
-16733>
jiong"
-16708>
jiu"
-16706>
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- android 天气预报 源代码
