今天开始学Android开发,搞了一下午就完成了两个小功能,大部分时间都在调试、熟悉环境,

Android开发环境对比VS无论是安装、使用、更新都不够方便,不过慢慢适应就好
 
完成功能如下:
功能一:显示当前系统时间
功能二:根据编号获取城市天气
 
 
View层:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
 
    <TextView
        android:id="@+id/show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/show"
        android:onClick="getCurrentDate"
        android:text="获取当前时间:" />
 
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="33dp"
        android:onClick="getWuHanWeather"
        android:text="获取城市天气:" />
 
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button1"
        android:text="1"
        android:ems="10" >
        
        <requestFocus />
    </EditText>
 

</RelativeLayout>  

 
功能一:显示当前系统时间
    public void getCurrentDate(View source) {
        TextView tv = (TextView) findViewById(R.id.show);
        tv.setText("当前时间:" + new java.util.Date());

}

 
功能二:根据编号获取城市天气
    TextView response;
    HttpClient httClient;
 
    public void getWuHanWeather(View source) {
        this.httClient = new DefaultHttpClient();
        this.response = (TextView) findViewById(R.id.show);
 
        accessSecret(source);
    }
 
    Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 0x123) {
                response.setText("");
                response.setText(msg.obj.toString() + "\n");
            }
        }
    };
 
    public void accessSecret(View v) {
        String type = "";
        int inputValue=Integer.parseInt(((EditText) findViewById(R.id.editText1)).getText().toString());
        if (inputValue== 1) {
            type = "101200101";
        } else {
            type = "101200401";
        }
 
        final String cityId = type;
        new Thread() {
            @Override
            public void run() {
                // 创建一个HttpGet对象
                String url = "http://www.weather.com.cn/adat/sk/" + cityId
                        + ".html";
                HttpGet get = new HttpGet(url);
 
                // HttpGet get = new HttpGet(
                // "http://www.weather.com.cn/adat/sk/101200101.html");
                try {
                    // 发送GET请求
                    HttpResponse httpResponse = httClient.execute(get);
                    String json = EntityUtils.toString(
                            httpResponse.getEntity(), "UTF-8");
 
                    Message msg = new Message();
                    msg.what = 0x123;
                    msg.obj = json;
                    handler.sendMessage(msg);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();

}  

 

android_我的第一个Android程序的更多相关文章

  1. android开发------第一个android程序

    好吧,现在我们就一起来写第一个android程序,看它带给了我们什么.sdk的使用和虚拟机的创建我就不说了.项目创建过程先略过,不太重要. 那第一个程序我们能学到什么知识呢?一起看吧.^-^ 在IDE ...

  2. Android学习笔记一之第一个Android程序

    /** *Title:总结昨天下午至今天上午的学习成果 *Author:zsg *Date:2017-8-13 / 一.了解Android 1.Android架构 Android大致可分为四层架构:L ...

  3. Android逆向 编写一个Android程序

    本节使用的Android Studio版本是3.0.1 首先,我们先编写一个apk,后面用这个apk来进行逆向.用Android Studio创建一个新的Android项目,命名为Jhm,一路Next ...

  4. delphi 10 Seattle 第一个Android程序

    delphi 10 Seattle 第一个Android程序 1.打开Delphi RAD Studio Seattle,如下图     2.选择black application 点击OK   3. ...

  5. 【Android实验】第一个Android程序与Activity生命周期

    目录 第一个Android程序和Activity生命周期 实验目的 实验要求 实验过程 1. 程序正常启动与关闭 2. 外来电话接入的情况 3. 外来短信接入的情况 4. 程序运行中切换到其他程序(比 ...

  6. 用代码如何检测一个android程序是否在运行

    /** * 检测一个android程序是否在运行 * @param context * @param PackageName * @return */ public static boolean is ...

  7. Android开发学习之三——第一个Android程序

    下面我们建立第一个Android程序. 打开Eclipse,开始如下步骤: 1.File ==> New ==> Android Application Project 出现如下窗口: 2 ...

  8. 分析你的第一个Android程序

    目录 分析你的第一个Android程序 Android模式的项目结构 切换项目结构模式 Project模式的项目结构 .gradle和idea app build(没有发现这个文件夹) gradle ...

  9. java Android SDK安装与环境变量配置以及开发第一个Android程序

    JAVA的安装与环境变量的配置 1.先下载JAVA,并且安装. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u3 ...

随机推荐

  1. python中orm框架学习

    安装sqlalchemy pip3 install sqlalchemy 创建表结构: from sqlalchemy import Column,String,create_engine from ...

  2. Drupal7导入语言包

    下载语言包 然后把包存放在profiles\standard\translations目录下,安装. 如果出现如下错误 1.错误有MySql数据库默认引擎innoDB引起,只要mysql\bin\my ...

  3. Servlet的doGet与doPost方法的区别与使用

    Servlet的doGet与doPost方法的区别与使用 2016年07月07日 13:05:13 阅读数:10222 一,区别 在使用表单提交数据到服务器的时候有两张方式可共选择,一个是post一个 ...

  4. python的tuple()

    描述 Python 元组 tuple() 函数将列表转换为元组. 语法 tuple()方法语法: tuple( seq ) 参数 seq -- 要转换为元组的序列. 返回值 返回元组. 实例 以下实例 ...

  5. swt MouseAdapter

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:     The method ...

  6. 苹果Swift可为Windows/Android开发软件了

    http://www.swifthumb.com/article-189-1.html http://iphone.tgbus.com/news/class/201502/20150211103418 ...

  7. Linux内核同步机制之(四):spin lock【转】

    转自:http://www.wowotech.net/kernel_synchronization/spinlock.html 一.前言 在linux kernel的实现中,经常会遇到这样的场景:共享 ...

  8. Java易错知识点(1) - 关于ArrayList移除元素后剩下的元素会立即重排

    帮一个网友解答问题时,发现这样一个易错知识点,现总结如下: 1.易错点: ArrayList移除元素后,剩下的元素会立即重排,他的 size() 也会立即减小,在循环过程中容易出错.(拓展:延伸到所有 ...

  9. Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: 不支持的特性

    mybatis插入数据时报错: Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or ...

  10. JavaScript秘密花园

    译文地址 bonsaiden.github.io/JavaScript-Garden/zh/#intro.authors 之前被人问到JS一些概念性的东西,感觉很模糊,可能层次比较浅,偏理论的东西实践 ...