今天开始学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();

}  

 

最新文章

  1. jquery控制文字内容溢出用点点点(…)省略号表示
  2. js高级程序设计(七)BOM
  3. vb.net下载代码
  4. The prefix &quot;mvc&quot; for element &quot;mvc:annotation-driven&quot; is not bound 的解决方法
  5. 如何调节datagridview中字体
  6. html5之canvas练习
  7. 【网络流24题】 No.15 汽车加油行驶问题 (分层图最短路i)
  8. 我也要这样写define、、
  9. 判断http 请求来自于手机还是PC
  10. CentOS克隆机器步骤,图文教程
  11. Poj3321 Apple tree
  12. SoupUI安装
  13. Android短信验证码倒计时
  14. Azkaban安装及分布式部署(multiple-executor)
  15. PHP array
  16. Ubuntu cd
  17. rpm-yum_install_software
  18. redis缓存数据架构实战
  19. MyBatis基本配置和实践(二)
  20. c++我在努力----第三次作业体会

热门文章

  1. 【hdu4436/LA6387-str2int】sam处理不同子串
  2. 【反演复习计划】【bzoj1011】zap-queries
  3. js面向对象编程(二)构造函数的继承(转载)
  4. Selenium2+python自动化73-定位的坑:class属性有空格【转载】
  5. Juel Getting Started
  6. 正则表达式、re、常用模块
  7. 蓝牙遥控小车设计(三)——Amarino和 Android手机重力感应控制
  8. EASYUI datagrid批量修改与提交
  9. (转帖)关于easyui中的datagrid在加载数据时候报错:无法获取属性&quot;Length&quot;的值,对象为null或未定义
  10. 51nod 1344 走格子【贪心/前缀和】