package a.a;

 import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText; public class AActivity extends Activity {
/** Called when the activity is first created. */ EditText Ev1; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); Ev1 = (EditText)findViewById(R.id.editText1); //第一种方式
Button Btn1 = (Button)findViewById(R.id.button1);//获取按钮资源
Btn1.setOnClickListener(new Button.OnClickListener(){//创建监听
public void onClick(View v) {
String strTmp = "点击Button01";
Ev1.setText(strTmp);
} }); //第二种方式
Button Btn2 = (Button) findViewById(R.id.button2);//获取按钮资源
Btn2.setOnClickListener(listener);//设置监听 } Button.OnClickListener listener = new Button.OnClickListener(){//创建监听对象
public void onClick(View v){
String strTmp="点击Button02";
Ev1.setText(strTmp);
} }; //第三种方式(Android1.6版本及以后的版本中提供了)
public void Btn3OnClick(View view){
String strTmp="点击Button03";
Ev1.setText(strTmp); }
}
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" /> <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3"
android:onClick="Btn3OnClick"/> <EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <requestFocus />
</EditText> </LinearLayout>

Android开发之onClick事件的三种写法(转)的更多相关文章

  1. Android开发之onClick事件的三种写法

    package a.a; import android.app.Activity; import android.os.Bundle; import android.view.View; import ...

  2. Android开发之onClick事件的实现

    算是从2015年开始学习android开发,目前把onClick的事件实现写下来,记录下,以备参考. 实现button的点击功能,让textView显示一行文字,最简单的onClick事件. 直接贴代 ...

  3. (转)Ext.Button点击事件的三种写法

    转自:http://maidini.blog.163.com/blog/static/377627042008111061844345/ ExtJs的写法太灵活了,现在收集了关于Button点击事件的 ...

  4. Android journey3 @点击事件的4种写法

    对于android布局中的控件,如Button等会有相应的点击事件去响应它所需要的功能,今天我们就以电话拨号器的代码说明下几种点击事件: package com.itheima.phone; impo ...

  5. 16_点击事件第三种写法_activity实现接口

    第一种写法是有名内部类,第二种写法是匿名内部类,第三种写法是MainActivity实现接口OnClickListener.直接让MainActivity实现了OnClickListener这个接口. ...

  6. Android笔记---点击事件的四种写法

    Android 点击事件的四种写法: 1. 以内部类的形式实现 OnClickListener 接口.定义点击事件 class MainActivity extents Activity{ // .. ...

  7. Android 触发Button按钮事件的三种方式

    1.新创建一个类 2.使用内部类 3.当多个button按钮时,为简化代码而创建的实例listener 贴代码: MainActivity.Java  文件: package com.android. ...

  8. Android开发之Touch事件分发机制

    原地址http://www.cnblogs.com/linjzong/p/4191891.html Touch事件分发中只有两个主角:ViewGroup和View.Activity的Touch事件事实 ...

  9. [Android]Java中点击事件的四种写法

    点击事件的必备条件:实现OnClickListener接口,重写onclick(View v)方法 以拨号简单案例为例,如下图效果: 逻辑流程: 获取点击对象,获取数据 给对象设置监听类 实现OnCl ...

随机推荐

  1. jQuery之点击弹出图标环形菜单

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  2. Servlet之创建与配置

    上篇已将介绍完了,下面来实践操作走一个: 首先在名为"com.caiduping"的包中创一个MyFilter的对象: 1 package com.caiduping; 2 3 i ...

  3. ios开发:GCD多线程

    ios有三种多线程编程技术,分别是NSThread,Cocoa NSOperation和GCD,GCD全称Grand Central Dispatch 是Apple开发的一个多核编程的解决方法,在iO ...

  4. 【leetcode】5. Longest Palindromic Substring

    题目描述: Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  5. GISer 应届生找工作历程(完结)

    有半个月没更博客了,前几天在学校准备这保研,因为没有时间复习高数自然就没有过.    也没啥的,我本来就不打算复习,就是看看运气咋样(哈哈).在昨天开始跑的招聘会,一天下来不同地方跑了三家挺累的,记录 ...

  6. Visual Studio通过Web Deploy发布网站报错:An error occurred when the request was processed on the remote computer.

    这个问题很奇怪,不管我怎么重启服务器和自己的开发机,都没有用. 在网上找了很多资料,有说可以尝试去读Windows的错误日志,然后通过日志找原因…(详见Stackoverflow:http://sta ...

  7. 《RedHatLinux系统修复视频(通过本地镜像)》

    此视频的测试环境: win7下安装的VMware    redhatlinux6.3系统的修复     以删掉kernel系统引导故障重新安装kernel为例 基于本地镜像来对系统进行修复 如疑问可留 ...

  8. java在线截图---通过指定的URL对网站截图

    如何以java实现网页截图技术 http://wenku.baidu.com/view/a7a8b6d076eeaeaad1f3305d.html http://blog.csdn.net/cping ...

  9. dom4j api 详解--XPath 节点详解

    dom4j api 详解 http://871421448.iteye.com/blog/1546955 XPath 节点 http://www.w3school.com.cn/xpath/xpath ...

  10. VB.NET转C#代码的工具

    比如VB.NET的代码: For Each prop In entity.Details.Properties.All(). OfType(Of Microsoft.LightSwitch.Detai ...