今天开始学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. [bzoj2427][HAOI2010]软件安装——强连通分量+树形DP

    题目大意 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和最大). 但是 ...

  2. bzoj 2115 路径xor和最大值

    首先我们可以将这张图转化为一棵树,其中可能有好多环,肯定是从1走到N,其中可能经过好多环, 因为我们不走N在的一支,最后还是会走回来,因为a xor b xor b=a,所以相当于没走,就是走了个环, ...

  3. bzoj 1878 SDOI2009树状数组 离线操作

    本来想写2120的,结果想起来了这个 我们先对于询问左端点排序,用树状数组存区间字母个数,对于每种字母, 第一次出现的位置记录为1,剩下的记录为0,然后记录下,每种颜色 后面第一个和他相同颜色的位置 ...

  4. linux tomcat 乱码

    使用vi编辑器编辑长文件时,常常是头昏眼花,也找不到需要更改的内容. 这时,使用查找功能尤为重要. 方法如下: 1.命令模式下输入“/字符串”,例如“/Section 3”. 2.如果查找下一个,按“ ...

  5. 4.flume实战(一)

    需求:从指定网络端口采集数据输出到控制台 使用flume的关键就是写配置文件 a)配置source b)配置channel c)配置sink d)把以上三个组件串起来 我们看一下官网给的配置文件 # ...

  6. 【C++】重载

    参考:黄邦勇帅 1.操作符重载函数作为类的成员和友元或者独立于类的区别: 当操作符重载函数作为类的成员函数时,操作符重载函数的参数会比作为友元或者独立于类的操作符重载函数少一个参数,因为操作符重载类成 ...

  7. js的变量的有效域

    function test(o) { var i=0; if(typeof o=="object") { var j=1; for(var k=0;k<10;k++) { c ...

  8. python的内存管理机制(zz)

    本文转载自:http://www.cnblogs.com/CBDoctor/p/3781078.html 先从较浅的层面来说,Python的内存管理机制可以从三个方面来讲 (1)垃圾回收 (2)引用计 ...

  9. python基础(字符串常用、数字类型转换、基本运算符与流程控制)

    一.字符串常用操作: #! /usr/bin/env python # -*- coding: utf-8 -*- # __author__ = "Z'N'Y" # Date: 2 ...

  10. AC日记——Rmq Problem bzoj 3339

    3339 思路: 恶心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...