android响应事件(按钮)的三种方式
来源:互联网 发布:中国报刊数据库 编辑:程序博客网 时间:2024/05/21 17:54
方式1 采用匿名内部类方法
button1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
System.out.println("button1 clicked");
}
});
方式2 采用activity实现OnClickListener接口
public class TaskActivity extends Activity implements ClickListener
{
public void onClick(View arg0)
{
if(arg0==button1)
System.out.println("button1 clicked");
else if (arg0==button2)
System.out.println("button2 clicked");
...
}
}
方式3 修改XML android:onClick 属性
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
Now, when a user clicks the button, the Android system calls the activity's selfDestruct(View) method. In order for this to work, the method must be public and accept a View as its only parameter. For example:
public void selfDestruct(View arg0) {
System.out.println("button1 clicked");
}
- android响应事件(按钮)的三种方式
- android响应事件(按钮)的三种方式
- android响应事件的三种方式
- Android响应按钮事件的4种方式
- Android Intent和按钮响应事件的几种方式
- Android学习笔记——Button(按钮)响应事件的四种方式
- Android 控件中事件响应的三种实现方式
- 【Android】控件和基本事件响应的三种方式
- 【Android】控件和基本事件响应的三种方式
- android 触发Button按钮事件的三种方式
- Android之Button按钮点击事件的三种方式
- Button按钮响应事件的2种实现方式
- wemall app商城源码中android按钮的三种响应事件
- 安卓点击按钮的三种响应方式
- android按键的三种响应方式
- android 为按钮添加响应事件的五种写法
- Android响应按钮点击事件的4种方法实现
- Android 响应按钮点击事件的4种写法
- [cocos2d-x学习之路]在mac上配置cocos2d-x开发环境
- 数据结构时间复杂度的计算
- 一 造成segment fault,产生core dump的可能原因
- Bloom Filter概念和原理
- 在linux中添加ftp用户,并设置相应的权限
- android响应事件(按钮)的三种方式
- 查询当前表可用序号的 一种方案
- itu ftp address
- 呕心沥血2个月,终于完成了我的高品质HIFI WAV播放器!终于不必为没有高质量音源而苦恼了:)
- Android TextView中设置超链接
- Looper
- PS图层混合模式详解
- Design:Widgets
- Hibernate的工具类HibernateUtils