文档章节

ManActivity改

 易水寒521
发布于 2015/05/26 16:44
字数 698
阅读 4
收藏 0

package com.weatherdemo;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{

 Button bt1, bt2,bt3;
 EditText ed;
 TextView tv;
 
 String weatherid,eh,temp1,temp2,sfdate,weather,date,sh,efdate;
 
 WeatherDemoLogic wLogic = null;

 List<Map<String, String>> str;
 int x;
 int i = 0;
 DateFormat df ;
 Date d=new Date();
 @SuppressLint("SimpleDateFormat")
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  df = new SimpleDateFormat("yyyy-MM-dd");
  bt1 = (Button) findViewById(R.id.button1);
  bt2 = (Button) findViewById(R.id.button2);
  bt3 = (Button) findViewById(R.id.button3);
  ed = (EditText) findViewById(R.id.editText1);
  tv = (TextView) findViewById(R.id.textView1);

  wLogic = new WeatherDemoLogic();

  bt1.setOnClickListener(this);
  bt2.setOnClickListener(this);
  bt3.setOnClickListener(this);
  
//  bt1.setOnClickListener(new View.OnClickListener() {
//
//   @Override
//   public void onClick(View arg0) {
//
//    bt1.setVisibility(View.VISIBLE);
//
//    try {
//     wLogic.WeatherDemo(ed.getText().toString());
//     str = wLogic.WeatherDemo(ed.getText().toString());
//
//    } catch (ClientProtocolException e1) {
//     e1.printStackTrace();
//    } catch (IOException e1) {
//     e1.printStackTrace();
//    } catch (JSONException e1) {
//     e1.printStackTrace();
//    }
//
//    x = str.get(0).size();
//
//    // System.out.println(str.get(0));
//    String weatherid = str.get(i).get("weatherid");
//    String eh = str.get(i).get("eh");
//    String temp1 = str.get(i).get("temp1");
//    String temp2 = str.get(i).get("temp2");
//    String sfdate = str.get(i).get("sfdate");
//    String weather = str.get(i).get("weather");
//    String date = str.get(i).get("date");
//    String sh = str.get(i).get("sh");
//    String efdate = str.get(i).get("efdate");
//    tv.setText("weatherid: " + weatherid + "\n" + "eh: " + eh
//      + "\n" + "temp1: " + temp1 + "\n" + "temp2: " + temp2
//      + "\n" + "sfdate: " + sfdate + "\n" + "efdate: "
//      + efdate + "\n" + "weather: " + weather + "\n"
//      + "date: " + date + "\n" + "sh: " + sh);
//
//   }
//  });
//
//  // 下一个
//  bt1.setOnClickListener(new View.OnClickListener() {
//
//   @Override
//   public void onClick(View arg0) {
//    if (i < x) {
//     i = i + 1;
//     
//     String weatherid = str.get(i).get("weatherid");
//     String eh = str.get(i).get("eh");
//     String temp1 = str.get(i).get("temp1");
//     String temp2 = str.get(i).get("temp2");
//     String sfdate = str.get(i).get("sfdate");
//     String weather = str.get(i).get("weather");
//     String date = str.get(i).get("date");
//     String sh = str.get(i).get("sh");
//     String efdate = str.get(i).get("efdate");
//     
//     tv.setText("weatherid: " + weatherid + "\n" + "eh: " + eh
//       + "\n" + "temp1: " + temp1 + "\n" + "temp2: " + temp2
//       + "\n" + "sfdate: " + sfdate + "\n" + "efdate: "
//       + efdate + "\n" + "weather: " + weather + "\n"
//       + "date: " + date + "\n" + "sh: " + sh);
//
//    } else {
//     System.out.println("超出界限");
//    }
//   }
//  });
 }

 @Override
 public void onClick(View arg0) {
  switch (arg0.getId()) {
  case R.id.button1:
   bt2.setVisibility(View.VISIBLE);
   bt3.setVisibility(View.VISIBLE);
   try {
    wLogic.WeatherDemo(ed.getText().toString());
    str = wLogic.WeatherDemo(ed.getText().toString());

   } catch (ClientProtocolException e1) {
    e1.printStackTrace();
   } catch (IOException e1) {
    e1.printStackTrace();
   } catch (JSONException e1) {
    e1.printStackTrace();
   }

   x = str.get(0).size();

   // System.out.println(str.get(0));
   weatherid = str.get(i).get("weatherid");
   eh = str.get(i).get("eh");
   temp1 = str.get(i).get("temp1");
   temp2 = str.get(i).get("temp2");
   sfdate = str.get(i).get("sfdate");
   weather = str.get(i).get("weather");
   date = str.get(i).get("date");
   sh = str.get(i).get("sh");
   efdate = str.get(i).get("efdate");
   
   try {
    d=df.parse(date);
    
   } catch (ParseException e) {
    e.printStackTrace();
   }
   tv.setText("weatherid: " + weatherid + "\n" + "eh: " + eh
     + "\n" + "temp1: " + temp1 + "\n" + "temp2: " + temp2
     + "\n" + "sfdate: " + sfdate + "\n" + "efdate: "
     + efdate + "\n" + "weather: " + weather + "\n"
     + "date: " + d + "\n" + "sh: " + sh);
   break;
  case R.id.button2:
   if (i < x) {
    i = i + 1;
    weatherid = str.get(i).get("weatherid");
    eh = str.get(i).get("eh");
    temp1 = str.get(i).get("temp1");
    temp2 = str.get(i).get("temp2");
    sfdate = str.get(i).get("sfdate");
    weather = str.get(i).get("weather");
    date = str.get(i).get("date");
    sh = str.get(i).get("sh");
    efdate = str.get(i).get("efdate");
    
    try {
     d=df.parse(date);
     
    } catch (ParseException e) {
     e.printStackTrace();
    }
    
    tv.setText("weatherid: " + weatherid + "\n" + "eh: " + eh
      + "\n" + "temp1: " + temp1 + "\n" + "temp2: " + temp2
      + "\n" + "sfdate: " + sfdate + " \n" + "efdate: "
      + efdate + "\n" + "weather: " + weather + "\n"
      + "date: " + d + "\n" + "sh: " + sh);
   } else {
    Toast.makeText(this, "超出界限", Toast.LENGTH_SHORT).show();
   }
   break;
  case R.id.button3:
   if(i>0){
    i=i-1;
    
    weatherid = str.get(i).get("weatherid");
    eh = str.get(i).get("eh");
    temp1 = str.get(i).get("temp1");
    temp2 = str.get(i).get("temp2");
    sfdate = str.get(i).get("sfdate");
    weather = str.get(i).get("weather");
    date = str.get(i).get("date");
    sh = str.get(i).get("sh");
    efdate = str.get(i).get("efdate");
    
    try {
     d=df.parse(date);
     
    } catch (ParseException e) {
     e.printStackTrace();
    }
    
    tv.setText("weatherid: " + weatherid + "\n" + "eh: " + eh
      + "\n" + "temp1: " + temp1 + "\n" + "temp2: " + temp2
      + "\n" + "sfdate: " + sfdate + "\n" + "efdate: "
      + efdate + "\n" + "weather: " + weather + "\n"
      + "date: " + d + "\n" + "sh: " + sh);
   }else {
    Toast.makeText(this, "不好意思!查不到前面的时间", Toast.LENGTH_SHORT).show();
   }
   break;
  default:
   break;
  }
  
 }
}

© 著作权归作者所有

上一篇: android天气1
下一篇: demo
粉丝 0
博文 130
码字总数 120077
作品 0
虹口
私信 提问
安卓学习-XML,JSON解析;SAX,DOM,PULL机制–SAX和PULL类似

一.XML解析 案例: 点击按钮控制台打印 person.xml Person.java activity_main.xml ManActivity.java 二.JSON解析 点击第一个按钮: 点击第二个按钮: 点击第三个按钮 点击第四个按钮: 引用...

少年不知愁滋味
2016/04/02
21
0
“币改”是九死一生的事情 ——互链脉搏“币改何去何从”圆桌主题对话

互链脉搏按:7月区块链凉风渐起,但“币改”提法一出,再次激发了从业人员分泌肾上腺素,一时间成为行业热议话题,币改的修正提法“票改”、“链改”也借机问世。 但“币改”究竟为何?其区块...

互链脉搏
2018/08/14
0
0
来公司半年多了,大概改了半年的BUG

来公司半年多了,大概改了半年的BUG,新的需求少的可怜。。。 基本上都是改BUG,问题在于改的BUG还都是人家的BUG, 或者说是别人不要改的BUG,改的很是郁闷。 我改怎么办

-卒-
2013/04/24
1K
19
ArrayList 和 CopyOnWriteArrayList

这篇文章的目的如下: 了解一下ArrayList和CopyOnWriteArrayList的增删改查实现原理 看看为什么说ArrayList查询快而增删慢? CopyOnWriteArrayList为什么并发安全且性能比Vector好 1. List接...

群星纪元
04/01
0
0
完整的权限管理系统 - LaySSH

LaySSH是一款完全开源免费的开发框架,基于LayUI+SpringMVC+Spring+Hibernate+Mysql搭建而成,内置代码生成器,能够快速生成增删改查代码,节省开发时间,快速构建企业级的web应用系统。 该框...

herun
2018/02/02
0
0

没有更多内容

加载失败,请刷新页面

加载更多

axios 使用步骤很简单,首先在前端项目中,引入 axios:

  前端网络访问,主流方案就是 Ajax,Vue 也不例外,在 Vue2.0 之前,网络访问较多的采用 vue-resources,Vue2.0 之后,官方不再建议使用 vue-resources ,这个项目本身也停止维护,目前建...

SEOwhywhy
37分钟前
4
0
c++ 创建对象的三种方法

c++有三种方法创建对象 结合代码来看 1 #include <iostream> 2 using namespace std; 3 class Test { 4 5 private: 6 public: 7 add() 8 { 9 ......

天王盖地虎626
51分钟前
1
0
ant 中的fileset include等拷贝

拷贝一个目录到指定目录下 例:<copy todir="${basedir}/new"> <fileset dir="${basedir}/old"> <include name="appgen" /> <include name="appgen/" /> <include name=appgen/**" /> <incl......

shzwork
57分钟前
2
0
react-jianshu项目的创建

创建项目 1、github上创建仓库react-jianshu 2、将项目克隆到本地git clone git@github.com:startjcu/react-jianshu.git 3、在当前目录(项目目录的上级目录)下执行create-react-app react-...

星闪海洋
今天
2
0
OSChina 周二乱弹 —— 小哥哥,你可以教我写代码吗

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @nnnm: 生活大爆炸,结束了,这部陪伴了漫长时间的情景喜剧,最终是以诺贝尔奖和大团圆收尾的。虽然,不算精彩,但也是温馨。而少年谢尔顿的...

小小编辑
今天
945
14

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部