WeatherdemoNew2

package com.weatherdemo.until;

public class Weather {
 private String resultcode;
 private String reason;
 private int error_code;
 private Demo demo;

 public Weather(String resultcode, String reason, Demo demo, int error_code) {
  super();
  this.resultcode = resultcode;
  this.reason = reason;
  this.error_code = error_code;
 }

 public int getError_code() {
  return error_code;
 }

 public void setError_code(int error_code) {
  this.error_code = error_code;
 }

 public Demo getDemo() {
  return demo;
 }

 public void setDemo(Demo demo) {
  this.demo = demo;
 }

 public String getResultcode() {
  return resultcode;
 }

 public void setResultcode(String resultcode) {
  this.resultcode = resultcode;
 }

 public String getReason() {
  return reason;
 }

 public void setReason(String reason) {
  this.reason = reason;
 }

 @Override
 public String toString() {
  return "Weather [resultcode=" + resultcode + ", reason=" + reason
    + ", demo=" + demo + "]";
 }

}

package com.weatherdemo.until;

import java.io.IOException;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class HttpUtil {
 // 提交请求
 public static HttpClient client = new DefaultHttpClient();
 
 public static String getRequest(String url,Map<String, String> params) throws ClientProtocolException, IOException{
  StringBuffer sb=new StringBuffer();
  String result="";
  sb.append("http://v.juhe.cn/weather/");
  sb.append(url);
  // 拼接参数
  if(params!=null){
   sb.append("?");
   for(Map.Entry<String, String> entry:params.entrySet()){
    String key=entry.getKey();
    String value=entry.getValue();
    sb.append(key + "=" + value + "&");
   }
  }
  // 删除最后的"&"
  sb.delete(sb.length()-1, sb.length());
  
  // 发送GET请求
  HttpGet get=new HttpGet(sb.toString());
  
  HttpResponse response=client.execute(get);
  HttpEntity entity=response.getEntity();
  result=EntityUtils.toString(entity);
  return result;
 }
}

package com.weatherdemo;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

 Button bt;
 EditText ed;
 WeatherDemoLogic wLogic=null;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  bt=(Button) findViewById(R.id.button1);
  ed=(EditText) findViewById(R.id.editText1);
  
  wLogic=new WeatherDemoLogic();
  
  bt.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    
    try {
     wLogic.WeatherDemo(ed.getText().toString());
     
     
    } catch (ClientProtocolException e) {
     e.printStackTrace();
    } catch (IOException e) {
     e.printStackTrace();
    } catch (JSONException e) {
     e.printStackTrace();
    }
   }
  });
 }
}

package com.weatherdemo.until;

public class Demo {
 private String weatherid;
 private String weather;
 private String temp1;
 private String temp2;
 private String sh;
 private String eh;
 private String date;
 private String sfdate;
 private String efdate;

 public Demo(String weatherid, String weather, String temp1, String temp2,
   String sh, String eh, String date, String sfdate, String efdate) {
  super();
  this.weatherid = weatherid;
  this.weather = weather;
  this.temp1 = temp1;
  this.temp2 = temp2;
  this.sh = sh;
  this.eh = eh;
  this.date = date;
  this.sfdate = sfdate;
  this.efdate = efdate;
 }

 public String getWeatherid() {
  return weatherid;
 }

 public void setWeatherid(String weatherid) {
  this.weatherid = weatherid;
 }

 public String getWeather() {
  return weather;
 }

 public void setWeather(String weather) {
  this.weather = weather;
 }

 public String getTemp1() {
  return temp1;
 }

 public void setTemp1(String temp1) {
  this.temp1 = temp1;
 }

 public String getTemp2() {
  return temp2;
 }

 public void setTemp2(String temp2) {
  this.temp2 = temp2;
 }

 public String getSh() {
  return sh;
 }

 public void setSh(String sh) {
  this.sh = sh;
 }

 public String getEh() {
  return eh;
 }

 public void setEh(String eh) {
  this.eh = eh;
 }

 public String getDate() {
  return date;
 }

 public void setDate(String date) {
  this.date = date;
 }

 public String getSfdate() {
  return sfdate;
 }

 public void setSfdate(String sfdate) {
  this.sfdate = sfdate;
 }

 public String getEfdate() {
  return efdate;
 }

 public void setEfdate(String efdate) {
  this.efdate = efdate;
 }

 @Override
 public String toString() {
  return "Demo [weatherid=" + weatherid + ", weather=" + weather
    + ", temp1=" + temp1 + ", temp2=" + temp2 + ", sh=" + sh
    + ", eh=" + eh + ", date=" + date + ", sfdate=" + sfdate
    + ", efdate=" + efdate + "]";
 }

}

你可能感兴趣的:(WeatherdemoNew2)