在Android1.6里面,添加Listener的工作变得相当的简单(感觉更像在做网页编程!),具体步骤如下:
1.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"      >  <TextView        android:layout_width="fill_parent"       android:layout_height="wrap_content"       android:text="@string/hello"      />  <Button       android:text="Button01"       android:id="@+id/Button01"       android:layout_width="wrap_content"       android:layout_height="wrap_content"      android:onClick="myClickHandler"      /> </LinearLayout> 

2. TestOnClickListener.java文件
package com.ray.test;    import android.app.Activity;  import android.os.Bundle;  import android.view.View;    public class TestOnClickListener extends Activity {           @Override      public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);      }      public void myClickHandler(View target){           switch (target.getId()) {           case R.id.Button01:                setTitle("myButton01");               break;            }      }  }  

这种方法学习了,呵呵

更多相关文章

  1. Android实现侧滑菜单
  2. android keystore文件转换格式为pk8和x509.pem
  3. Android常见UI组件之ListView(二)——定制ListView
  4. android JNI utils/Log.h 找不到 解决方法
  5. Android中加载PNG图片时出现错误----No resource found
  6. 获取一个app的package名和activity名
  7. Android内存泄露检测工具 LeakCanary 使用 及 MAT分析
  8. Android应用篇 - app 签名与加固原理分析
  9. Android接口描述语言。

随机推荐

  1. 导入color文件中的颜色值 android
  2. android webview pre[name=code] syntaxH
  3. android CursorAdapter
  4. 4.8.4 在Android 中fragment中获取上下文
  5. android studio 新建activity
  6. Android 开发入门-ListView 的用法
  7. android 图片圆角 遮罩_安卓圆角、背景遮
  8. 前端 Notes | H5 打开 App 并跳转指定页(An
  9. 为什么说android UI操作不是线程安全的
  10. exp:Android Studio调试系统源码的方法 (干