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

编程入门 行业动态 更新时间:2024-10-13 16:21:05

android<a href=https://www.elefans.com/category/jswz/34/1768915.html style=天气预报获取,android 获取天气预报例子源码"/>

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

【实例简介】

【实例截图】

【核心代码】

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=".html";

//public static String url2=".html";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

getInfo(cityCode);

}

public void getInfo(String cityCode){

String url="=" 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);

}

}

更多推荐

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

本文发布于:2024-03-04 17:06:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1709867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:天气预报   源码   例子   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!