在好例子网,分享、交流、成长!
您当前所在位置:首页Others 开发实例一般编程问题 → android项目 -天气预报详解实例

android项目 -天气预报详解实例

一般编程问题

下载此实例
  • 开发语言:Others
  • 实例大小:1.16M
  • 下载次数:7
  • 浏览次数:225
  • 发布时间:2020-11-01
  • 实例类别:一般编程问题
  • 发 布 人:robot666
  • 文件格式:.pdf
  • 所需积分:2
 

实例介绍

【实例简介】
android项目 -天气预报详解实例
12. if(en Week. equals("Mon")l en Week. equals("Monday ) 13. return"星期 14. clsc if(cn Wcck. cquals("Tuc")I cn Wcck.cquals("Tuesday)) L5. return"星期二"; 16. else if (en Week. equals("Wed")l en Week. equals( Wednesday ) 17. return"星期 18. else if (en Week. equals( Thu)l en Week. equals( Thursday ) 19. return"星期四"; 20. else if (en Week. equals("Fri")lI en week. equals(Friday ) 21. return"星期五"; 22. clsc if (cn Wcck. cquals("Sat") cn Wcck. cquals("Saturday")) 23.etu"星期六" 24. else if (en Week. equals("Sun")Il en Week. equals("Sunday ) 25. return"星期日"; 6. return 27. 28. public static String weather( String en Weather)I 29. if (en Weather. equals("Clear")) 30 return"晴"; 31. else if (en Weather equals("Partly Sunny") 32. Il en Weather equals(partly_cloudy)) 33.reur"多云" 34. else if(en Weather equals("Chance of Rain) 35 return”晴转雨"; 36. else if (en Weather equals("storm")) 37.reun"暴N" 38. else if (en Weather equals( thunderstorm")) 39.reum"雷阵丽"; 40. else if(en Weather equals("fog")) 41.reun"大雾"; 42. else if (en Weather. equals"haze")) 43. return"有雾 44. else if (en Weather equals("rain")) 45. return"刚"; 46. else if (en Weather equals"heavyrain") 47. return"大网": 48. else if (en Weather equals("lightrain" )) 49. return"小网" 50. else if(en Weather equals( heavyrain) 51. return 大 52. else if (en Weather. equals( 3. return"有雪"; ∥/还需要补充 55. return 56. 57. public static Bitmap return BitMap(String imgUrl)I 58. URL mylmg Url = null 59. Bitmap bitmap=null 61. mylmgUrl =ncw URL(imgUrl); 62. catch(MalformedURLException e)( 63. e printStackTraceO 66.HttpurlconnccTionconn=(httpurlconncction)Mylmgurl 67.. open Connectiong) 68. conn, set DoInput( true 69. conn connecto 70. InputStream is= conn. getInputStream( 71. bitmap= Bitmap Factory decode stream(is) 72. is close( 73. catch(IOEXception e) I 74 e print StackTraceO 76. return bitmap: 77. 78 复,代码 4。开始真正的T作咯。下面的程序通过〔 Google提供的api来获取天气预报信息 1. package com. sbs. weather 3. import java. io InputStream 4 5. import javax. xml parsers Document Builder 6. import javax. xml parsers Document BuilderFactory 8.importorg.apachehttphttpentity 9.importorgapachehttpHttpresponse; 1o.importorgapache.http.client.methods.Httpget I1.importorgapachc.httpclicnt.methodsHttpurircqucSt; 12.importorgapachehttpimplclient.Defaulthttpclient; 13.importorgapachehttputilEntityutils 14. import org.w3cdom Document; 15. import oig w3c dom Nodelist nl. sax. Inputsourc 18. import android app. Activity 19. import android. graphics. Bitmap 20. import android os Bundle; 21. import android os. Handler 22 import android os Message 23. import android util. Log 24. import android viewView, 25. import android. widget. Button; 26. import android. widget. EditTcxt 27. import android widget. Image view 28. import android. widget. Text view: 30. public class Weather extends Activity 32. public Edit'Text emplace 33. public Text view TvPlace 34. public: Button query 35. public Text View placename 36. public Image View im view: 38./** Called when the activity is first created. s/ 39. Override 40. public void on Create(Bundle savedInstance State)I 41. super on Create( savedInstanceState); 42. set Content view (. layout main) 43 44. ETplace =(EditText)find View Byld(Rid place) 45. query =(Button)find View Byld (rid query 46. im View =(Image View )find View Byld(R id my Image View) 47. placeName =(Text view)findView Byld(R id placeName) 48 49. query. setOnClick Listener(new Button. OnclickListenero 50. public void onC lick View v)( 52. T'vPlace =(Text View )find View Byld(R id. tvPlace ) 54. String place= CntoEn getFullSpell(ETplace getText toString)) 55. placeName setText(place); 56. String weather= 57.Stringurl="http://www.googlecom/ig/api?&weather="+place 58.deFaulthttpclientclientsnewDefaulthttpclient(; 59. Httpuri Request req = new Http Get(url): 60. Httpresponse resp client execute(req); 61 62. //String strRcsult= EntityUtils to String(rcsp. gctEntityo) 63. //Log.i("weather->, strResult): 〃一华氏度等于9/5摄氏度数值+32 66. Httpentity ent=resp. getentitY(: 67. InputStream stream ent getContento 8 69. DocumentBuilder b= Document BuilderFactory newInstanceo 70.. ncw Document Builder: 71. Document d=b parse(new InputSource(stream) 72. NodeList n =d. getElements B yTagName(forecast_conditions") 74.∥获待图片url当人的。 75.Stringimgcrl="httP://www.google.com 76 imgUrl+= n item(O).getChildNodes(). item(3).get Attributes.item( 0)-getNode value( 77. im View. setlmageBitmap(Utils. return BitMap(imgUrl)) 78 79.∥今后4人预报 80. for (int i=0: i< n.getLength (: i++)( 81. weather += Utils. week/ n item().get ChildNodesO item(O) 82.getAttributes( item(0).getNode value) 83. weather + 84. weather + (Inte 85. parseInt(n item(i).get ChildNodesO item(1) 86. getAttributes( item(0). getNode valueD)-32)*5:9 87. weather +=1 88. weather +=(Integer 89. parseInt(n item(i).get ChildNodesO item(2) 90.. getAttributes(item(O). getNode ValueD)-32)*5/9 91. weather +E 92. weather + Utils weatherin. item(i). get childNodeso item( 4) 93. getAttributes(). item(0). getNode Value) 94 weather+="\n" 95 96. Log. i("parsed weather->", weather 97.TvPlace. set'lext( weather); 98 99.1 catch(Exception e)i 100. e-print Stack Trace( 101.} 3.}) 105,} 复制代码 5。嗯这一步相当重要,就是添加权限。要是没冇权限一切白搭 1. <?xml version="1. 0"encoding="utf-8 9> 2.manifestxmlns:android="http://schemas.androidcom/apk/res/android 3. package="com. sbs. weather 4. android: version code="1 5. android versionNane="1. 0">> 6. <uses-permission android name="android. permission. INTERNET ></uses-permissionz 7. <application android: icon=@drawable/icon"android: label="@ string/app_name 8. <acLivily android: larne=. weather" 9. android: label="@ string/app_name"> 10. <intent-filter> ll. saction android name= android intent, uction man/> 12. <category android: name="android. intent. category. LAUNCHER"/> 13. dintent-filter> 14. </activity> 15 16. </application> 17. </manifest 复闹代码 6。开始运行咯。 @55s54AVD20 www: eoeAndroid com 面8:22AM 中文天气预报深白色 输入城市名称(汉字或者拼音) 查询 bei jing 北京背景被呗北小 QWER T Iop AS DFGHKL Z NM岛 中文m。 55Av20 www.eoeandroid.com 9:28AM 中文天气预报一深白色 北京 星期三,27-37,晴 星期四,26-35,晴 星期五,26-38,晴 星期六,21-28,晴转雨 北京 市大学时间人 QWERTYUIOP ASDFGHKL ZXCVB NM器 中文?123 源码在这里 sbs Weather rar(64.82 KB) 喜欢的下载吧。 咽唧,我是好人! 7。总结:可以便用数据库,保存用户常用的设置。比如存5个城市等 还可以加上触屏拖动切换城巾的效果这样了就比较完美了。 当然为了节省流量完仝可以使用本地图片而不用刈络图片。 总之希望各位朋友,尤其是大牛们,提出建议,帮着完善。 02.png(28.52B) 5354AvD20 www.eoeandroid.com 8:35AM 中文天气预报一深白色 星期三,27-37,晴 星期四,26~35,晴 星期五,26-38,晴 星期六21-28,隋转雨 北京 查询 市大学时间人 QWER P ASDFGH了kt Z X CVBNMa 中文?123 【实例截图】
【核心代码】

标签:

实例下载地址

android项目 -天气预报详解实例

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警