基本信息
源码名称:android 获取天气预报例子源码
源码大小:1.61M
文件格式:.rar
开发语言:Java
更新时间:2015-08-12
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.weatherinfo; import com.getweatherinfo.GetWeateherInfo; import com.getweatherinfo.WeatherJson; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; public class MainActivity extends Activity { public static String cityCode="101280800"; //public static String url="http://www.weather.com.cn/data/cityinfo/101010100.html"; //public static String url2="http://www.weather.com.cn/data/sk/101010100.html"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getInfo(cityCode); } public void getInfo(String cityCode){ String url="http://weather.51wnl.com/weatherinfo/GetMoreWeather?cityCode=" cityCode "&weatherType=0"; String weatherDetail = "123"; try { weatherDetail = GetWeateherInfo.getRequest(url); Log.d("shit", weatherDetail); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } TextView showTxt=(TextView)findViewById(R.id.showTxt); showTxt.setText(WeatherJson.weatherJson(weatherDetail)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { // TODO Auto-generated method stub if(item.getItemId()==R.id.beijing){ cityCode="101010100"; getInfo(cityCode); }else if(item.getItemId()==R.id.shenzhen){ cityCode="101280601"; getInfo(cityCode); }else if(item.getItemId()==R.id.foshan){ cityCode="101280800"; getInfo(cityCode); }else if(item.getItemId()==R.id.guangzhou){ cityCode="101280101"; getInfo(cityCode); }else if(item.getItemId()==R.id.dongguan){ cityCode="101281601"; getInfo(cityCode); }else if(item.getItemId()==R.id.changsha){ cityCode="101250101"; getInfo(cityCode); } return super.onMenuItemSelected(featureId, item); } }