1.Activity是Android组件中最基本也是最为常见用的四大组件(Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器)之一。

Activity中所有操作都与用户密切相关,是一个负责与用户交互的组件,可以通过setContentView(View)来显示指定控件
在一个android应用中,一个Activity通常就是一个单独的屏幕,它上面可以显示一些控件也可以监听并处理用户的事件做出响应。Activity之间通过Intent进行通信。
 
2.程序1
activity_main.xml
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText android:text="EditText01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/edtInput"></EditText>
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show" android:id="@+id/btnShow"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Clear" android:id="@+id/btnClear"></Button>
</LinearLayout>
<AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" >
<TextView android:text="TextView01"
android:id="@+id/TextView01"
android:layout_height="wrap_content"
android:layout_y="10px"
android:layout_width="wrap_content"
android:layout_x="110px">
</TextView>
</AbsoluteLayout>
</LinearLayout>

MainActivity.java

public class MainActivity extends ActionBarActivity {

    Button btnShow;
Button btnClear;
EditText edtInput; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); btnShow = (Button)findViewById(R.id.btnShow);
btnClear = (Button)findViewById(R.id.btnClear);
edtInput = (EditText)findViewById(R.id.edtInput);
btnShow.setOnClickListener(new ClickListener());
//绑定匿名的监听器,并执行您所要在点击按钮后执行的逻辑代码
btnClear.setOnClickListener(new ClickListener()); // if (savedInstanceState == null) {
// getSupportFragmentManager().beginTransaction()
// .add(R.id.container, new PlaceholderFragment()).commit();
// }
} class ClickListener implements OnClickListener
// 使用自定义内部类继承监听器抽象类,并实现抽象方法。
{
public void onClick(View v)
{
if(v==btnShow)
{
new AlertDialog.Builder(MainActivity.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Information")
.setMessage(edtInput.getText())
.show(); }
else if(v==btnClear)
{
edtInput.setText("HelloAndroid");
}
}
}

http://blog.csdn.net/hellogv/article/details/4515763

监听器是个抽象类,它包含了一个事件触发时系统会去调用的函数

每个监听器都是跳转到一个新的activity

监听器的函数命名规则是setOn****Listener

或者是   也可以使用Java提供的抽象类的匿名实现

  @Override
2 public void onCreate(Bundle savedInstanceState) {
3 super.onCreate(savedInstanceState);
4 setContentView(R.layout.main);
5 Button btn = (Button)findViewById(R.id.btnOK);
6 //绑定匿名的监听器,并执行您所要在点击按钮后执行的逻辑代码
7 btn.setOnClickListener(new View.OnClickListener() {
8
9     @Override
10      public void onClick(View arg0) {
11      // TODO Auto-generated method stub
12      Toast.makeText(MyActivity.this, "点击了按钮", Toast.LENGTH_LONG).show();
13     }
14   });
15 }

Toast 是一个 浮动显示的View 视图(少量信息)。

程序2

main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>
 package com.LayoutDemo;
import com.LayoutDemo.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class LayoutDemo extends Activity {
/** Called when the activity is first created. */
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP = ViewGroup.LayoutParams.FILL_PARENT; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//新建TableLayout01的实例
TableLayout tableLayout = (TableLayout)findViewById(R.id.TableLayout01);
//全部列自动填充空白处
tableLayout.setStretchAllColumns(true);
//生成10行,8列的表格
for(int row=0;row<10;row++)
{
TableRow tableRow=new TableRow(this);
for(int col=0;col<8;col++)
{
//tv用于显示
TextView tv=new TextView(this);
tv.setText("("+col+","+row+")");
tableRow.addView(tv);
}
//新建的TableRow添加到TableLayout
tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC));
}
}
}

http://blog.csdn.net/hellogv/article/details/4523745

3.

android:id="@+id/btnOK"

+表示通过它来生成静态资源,如果没有+,表示使用的是指定位置的静态资源,一般为控件赋ID时,都使用+这个方法

Android-第二天的更多相关文章

  1. 第一行代码 Android 第二版到货啦

    今日android第一行代码[第二版]已到,收获的季节到了 先看一下封面 书签: 以后就把空闲时间送给它吧 先来看一下本书的目录: 第1章 开始启程--你的第1行Android代码 第2章 先从看得到 ...

  2. (转).net程序员转战android第二篇---牛刀小试

    上篇说道如何搭建android的开发环境,这一篇我们将牛刀小试一下, 完成我们第一个android APP应用. 我就从新建项目说起吧. 首先打开Eclipse,选择顶部的File(文件)——new( ...

  3. (转).net开发者对android第二周的学习体会

    这一周相对没有春节时这么闲了,白天也比较多的工作要做,每天晚上又要被我三岁的女儿折腾到十点, 实在没有多少时间学习.在前一周的基础上,这周我试着自己练习写了一个个人管理的android的程序,主要实现 ...

  4. 疯狂Android第二章:Adapter以及部分控件使用

    第二章 重点:1.理解View以及各种布局的优缺点,适用场景. 2.熟练掌握adapter原理与用法. 3.熟悉其它控件的基本使用方法. /////////////////////////////// ...

  5. .net程序员转战android第二篇---牛刀小试

    上篇说道如何搭建android的开发环境,这一篇我们将牛刀小试一下, 完成我们第一个android APP应用. 我就从新建项目说起吧. 首先打开Eclipse,选择顶部的File(文件)——new( ...

  6. 我的Android第二章

    前言 之前有很多人遇到了关于内部类的问题[主要在android的学习之中会大量的使用到],内部类是什么,内部类怎么定义,内部类的分类,内部类的好处,内部类如何访问,这里我们来结合代码简单的理解一下 1 ...

  7. android第二天(项目的组成结构)

    1:src文件夹分析: helloWorld----src(源码文件夹) MainActivity:主界面类----gen(自动生成的源码文件夹) R.java:对应res文件夹 下面又包含三个内部类 ...

  8. 我的Android第二章:Android目录结构

    嗨!各位,小编又和大家分享知识啦,在昨天的博客笔记中小编给大家讲解了如何去配置Android工具以及SDK中的一些配置,那在今天的学习小编会带给大家哪些Android知识呢?首先我们看一下今天的学习目 ...

  9. "浅谈Android"第二篇:活动(Activity)

        距离上一篇文章,过去有半个多月了,在此期间忙于工作,疏于整理和总结,特此写下这篇博文,来谈谈自己对Activity的理解.总所周知,Activity组件在Android中的重要性不言而喻,我们 ...

  10. Android第二天

    1.从看得见的活动入手 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...

随机推荐

  1. grep命令及基本正则表达式

    grep命令是Linux系统中一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来. grep可用于shell脚本,因为grep通过返回一个状态值来说明搜索的状态,如果模板搜索成功 ...

  2. Head First设计模式之工厂模式

    一.定义 定义了一个创建对象的接口, 但由子类决定要实例化的类是哪一个. 工厂方法让类把实例化推迟到子类 二.结构 1.抽象工厂角色:这是工厂方法模式的核心,它与应用程序无关.是具体工厂角色必须实现的 ...

  3. ssh的action校验内容输出

    当form里为input类型时,如<input type="text" name="manager.name" />,则在对应的jsp中要使用< ...

  4. 【Python3之匿名函数及递归】

    一.匿名函数及内置函数补充 1.语法 Python使用lambda关键字创造匿名函数.所谓匿名,意即不再使用def语句这样标准的形式定义一个函数. 语法: lambda [arg1[, arg2, . ...

  5. Git-分布式版本控制系统(二)

    工作区(Woring directory ) 版本区(repository,即隐藏的.git文件) Git的版本库里存了很多东西,其中最重要的就是称为stage(或者叫index)的暂存区,还有Git ...

  6. ionic2 App搭建(三)

    cmd命令提示框中进入项目文件夹 运行命令 ionic serve --lab  结构如下图 这里数据是没有接受到的,是因为跨域的问题,解决方案是谷歌浏览器配置跨域指令如下: 配置chrome浏览器允 ...

  7. 豹哥嵌入式讲堂:ARM开发之文件详解(4)- relocatable文件(object, library)

    大家好,我是豹哥,猎豹的豹,犀利哥的哥.今天豹哥给大家讲的是嵌入式开发里的relocatable文件(object, library). 前三节课里,豹哥都是在给大家介绍嵌入式开发中的input文件. ...

  8. ETL实践--kettle转到hive

    ETL实践--kettle只做源数据的抽取,其他数据转换转到hive上. 1.用hive代替kettle的数据关联的原因 (1).公司之前的数据ELT大量使用了kettle.用kettle导原始数据速 ...

  9. Android 屏幕刷新机制

    这次就来梳理一下 Android 的屏幕刷新机制,把我这段时间因为研究动画而梳理出来的一些关于屏幕刷新方面的知识点分享出来,能力有限,有错的地方还望指点一下.另外,内容有点多,毕竟要讲清楚不容易,所以 ...

  10. 一次Oracle宕机切换后产生ORA错误的处理过程

    问题背景 机房意外断电后Oracle主服务器启动失败,Oracle备机接管 为了安全,管理员对于数据库做expdp的逻辑备份.但备份时发现AttributeInstance表备份失败,提示ORA-01 ...