gridlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_columnSpan="2"
android:hint="To:"
android:layout_gravity="fill"
android:inputType="textWebPassword"
android:maxLength="6"
/>
<!--inputType phone只输入电话号码
inputType="numberPassword" 只输入数字
textWebPassword 字母和数字
date 日期
maxLength 最大长度
-->
<EditText
android:layout_columnSpan="2"
android:hint="Subject:"
android:layout_gravity="fill"
android:editable="false"/>
<!--editable 只读-->
<EditText
android:layout_columnSpan="2"
android:hint="Message:"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:gravity="top"
/>
<Button
android:text="RESET"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:id="@+id/reset"
/>
<Button
android:text="SENO"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:id="@+id/send"
/> </GridLayout>

MainActivity  内部类实现

package com.hanqi.application3;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast; /**
* Created by Administrator on 2016/3/27.
*/
public class MainActivity extends Activity implements View.OnClickListener{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridlayout);
//添加监听器
//监听器 本身只是是一个接口,需要写实现类
Button bt_Reset=(Button)findViewById(R.id.reset);
//setOnClickListener设置监听器实现类的实例
//bt_Reset.setOnClickListener(new ButtonOnClickListener());
//当前Activity作为监听器接口的实现类
bt_Reset.setOnClickListener(this);
//监听器 本身只是是一个接口,需要写实现类
Button bt_Send=(Button)findViewById(R.id.send);
//setOnClickListener设置监听器实现类的实例
//bt_Send.setOnClickListener(new ButtonOnClickListener()); //匿名内部类
bt_Send.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
//强转
Button bt=(Button)v;
//bt.getText获取内容
String string =bt.getText().toString();
//Toast.makeText 提示框
//在内部调用外部类的实例:外部类的类名.this
Toast.makeText(MainActivity.this,string+" 按钮匿名内部类被点击了",Toast.LENGTH_LONG).show();
} }); }
//1.用内部类实现监听器接口
//implements 表示实现 OnClickListener 方法
private class ButtonOnClickListener implements View.OnClickListener
{
//传递的View参数 是触发事件的视图实例
public void onClick(View v)
{
//强转
Button bt=(Button)v;
//bt.getText获取内容
String string =bt.getText().toString();
//Toast.makeText 提示框
//在内部调用外部类的实例:外部类的类名.this
Toast.makeText(MainActivity.this,string+" 按钮被点击了",Toast.LENGTH_LONG).show();
}
} //传递的View参数 是触发事件的视图实例
public void onClick(View v)
{
//强转
Button bt=(Button)v; //bt.getText获取内容
String string =bt.getText().toString();
//Toast.makeText 提示框
Toast.makeText(this,string+" click",Toast.LENGTH_LONG).show();
} }

WaiBuListener  外部实现

package com.hanqi.application3;

import android.view.View;
import android.widget.Button; /**
* Created by Administrator on 2016/3/28.
*/
public class WaiBuListener implements View.OnClickListener {
public void onClick(View v)
{
//强转
Button bt=(Button)v;
//bt.getText获取内容
String string =bt.getText().toString();
//Toast.makeText 提示框
//在内部调用外部类的实例:外部类的类名.this
//Toast.makeText(MainActivity.this, string + " 按钮匿名内部类被点击了", Toast.LENGTH_LONG).show();
} }

andorid UI事件 监听器的更多相关文章

  1. andorid UI事件

  2. passive 的事件监听器

    很久以前,addEventListener() 的参数约定是这样的: addEventListener(type, listener, useCapture) 后来,最后一个参数,也就是控制监听器是在 ...

  3. Android事件监听器Event Listener

    在 Android 中,我们可以通过事件处理使UI与用户互动(UI Events). UI的用户事件处理,即View处理用户的操作,在应用程序中几乎不可避免.View是重要的类,它是与用户互动的前线: ...

  4. Android学习笔记--处理UI事件

    Handling UI Events 在Android里, 有不只一种方式可以截获用户与你的应用程序交互的事件. 在你的界面上处理事件时,你需要捕获用户与某个View实例交互时所产生的事件.View类 ...

  5. passive 的事件监听器(转载)

    passive 的事件监听器 很久以前,addEventListener() 的参数约定是这样的: addEventListener(type, listener, useCapture) 后来,最后 ...

  6. js事件监听器用法实例详解

    这篇文章主要介绍了js事件监听器用法,以实例形式较为详细的分析了javascript事件监听器使用注意事项与相关技巧,需要的朋友可以参考下本文实例讲述了js事件监听器用法.分享给大家供大家参考.具体分 ...

  7. Java基础之处理事件——实现低级事件监听器(Sketcher 2 implementing a low-level listener)

    控制台程序. 定义事件监听器的类必须实现监听器接口.所有的事件监听器接口都扩展了java.util.EventListener接口.这个接口没有声明任何方法,仅仅用于表示监听器对象.使用EventLi ...

  8. [原创]java WEB学习笔记48:其他的Servlet 监听器:域对象中属性的变更的事件监听器 (3 个),感知 Session 绑定的事件监听器(2个)

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  9. Android编程: 界面组成、事件监听器

    学习知识:界面组成.事件监听器 ====界面组成==== 1.用户界面的基本组件叫做View,都是继承android.view.View类,Android里面预定义很多基本的界面组件,比如 Butto ...

随机推荐

  1. C# 依赖注入那些事儿

    原文地址:http://www.cnblogs.com/leoo2sk/archive/2009/06/17/1504693.html 里面有一个例子差了些代码,补全后贴上. 3.1.3 依赖获取 u ...

  2. qt 中的基本知识

    1. 由 .ui 文件生成界面头文件: uic -o ui_dialog.h dialog.ui 2. 在工程目录下生成与平台无关的工程文件 : qmake -project 3. 生成与平台相关的  ...

  3. 微信小程序--分享报错(thirdScriptError Cannot read property 'from' of undefined;at pages/index/index page onShareAppMessage function TypeError: Cannot read property 'from' of undefined)

    分享功能: onShareAppMessage: function (res) { if (res.from === 'button') { // 来自页面内转发按钮 console.log(res. ...

  4. sass 使用clac的问题

    最后在github的issue中找到了方法,要想在sass的calc中使用变量,必须对这个变量使用sass的插值方法(#{$variable}). 所以把代码改正下面的形式就可以了: width: c ...

  5. webservice客户端 get delete post 请求

    package com.cn.eport.util.common; import java.io.IOException; import java.util.List; import org.apac ...

  6. IDEA错误:Cannot start compilation: the output path is not specified for module "Test". Specify the out

    错误是发生在从github上checkout自己的项目时.因为没有将配置文件一起上传,所以在运行Java程序时有了这个报错: Cannot start compilation: the output ...

  7. idea使用maven打包jar包

    1.在pom.xml中加入以下内容: <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  8. Jenkins-cli基本用法

    基本的格式为 java -jar jenkins-cli.jar [-s JENKINS_URL] command [options][args] 下面具体介绍各个命令的作用及基本使用方法 1.    ...

  9. POJ-3126.PrimePath(欧拉筛素数打表 + BFS)

    给出一篇有关素数线性筛和区间筛的博客,有兴趣的读者可以自取. 本题大意: 给定两个四位的素数,没有前导零,每次变换其中的一位,最终使得两个素数相等,输出最小变换次数.要求变换过程中的数也都是素数. 本 ...

  10. TOJ4127: Root of String

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4127 4127: Root of ...