天气预报获取,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 获取天气预报例子源码
发布评论