android天气预报获取,android 获取天气预报例子源码

【实例简介】

【实例截图】

61e865bab3d6d6c6fab66653247a6dca.png

【核心代码】

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);

}

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值