单击事件的三种写法.
来源:互联网 发布:滑稽表情知乎 编辑:程序博客网 时间:2024/05/04 03:19
package cn.itcast.phone;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity implements OnClickListener {public static final String tag ="MainActivity";private EditText mEditText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 得到了 activity界面上button的引用 Button button = (Button) this.findViewById(R.id.bt_dail); mEditText = (EditText) MainActivity.this.findViewById(R.id.et_number); /* button.setOnClickListener(new OnClickListener() { // 方法二 :通过匿名内部类的方式实现点击事件 @Overridepublic void onClick(View v) {String number = mEditText.getText().toString();Log.i(tag,number);Log.i(tag,"匿名内部类");//播打电话号码 Intent intent = new Intent(); // 意图 代表一个要执行动作的意图 //拨打动作 110 代表的是一个数据 intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:"+number));//android里面 startActivity(intent);}});*/ // button.setOnClickListener(this); } /** * 第一种写法 * @author zehua * */ private class MyButtonClickListener implements OnClickListener{ // 在某一个view对象 被点击的时候 调用的回调方法 @Overridepublic void onClick(View v) {String number = mEditText.getText().toString();Log.i(tag,number);//播打电话号码 Intent intent = new Intent(); // 意图 代表一个要执行动作的意图 //拨打动作 110 代表的是一个数据 intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:"+number));//android里面 startActivity(intent);} } // 按钮对应的点击事件 // 参数 v 代表的就是当前被点击的条目对应的view对象 @Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.bt_dail://相应按钮的点击事件 String number = mEditText.getText().toString();Log.i(tag,number);//播打电话号码 Intent intent = new Intent(); // 意图 代表一个要执行动作的意图 //拨打动作 110 代表的是一个数据 intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:"+number));//android里面 startActivity(intent); break; }} /** * 定义 xml布局文件里面 button 绑定的点击事件的方法 * @param view */ public void dail(View view){ String number = mEditText.getText().toString();Log.i(tag,number);//播打电话号码 Intent intent = new Intent(); // 意图 代表一个要执行动作的意图 //拨打动作 110 代表的是一个数据 intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:"+number));//android里面 startActivity(intent); } public void textview_click(View view){ Log.i(tag,"文本被点击了"); }}
0 0
- 单击事件的三种写法.
- Android 单击事件的几种写法
- [note]Android按钮单击事件的三种常用写法总结
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- 按钮单击事件的四种写法(转)
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种写法—笔记
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- Android按钮单击事件的四种常用写法总结
- IOS的一个关于球碰撞的小游戏
- CakePHP 开发(一)快速开发基本功能的项目
- ALAsset 将资源转换为 NSData
- ThinkPHP实现一键清除缓存方法
- TCP协议详解(上)
- 单击事件的三种写法.
- ASP在ACCESS中模糊查询"内存溢出"的解决方法
- 富士通半导体样片申请心得
- How to use the Human WorkFlow Web Services
- Crontab的格式
- vector中erase用法注意事项
- poj 2503 字典树
- 用python登录Dr.com思路以及代码分享
- 检测内存泄漏的办法