Button的3种单击事件监听器设置
2015-09-02 10:17
295 查看
<Button android:id="@+id/button4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/edit_text1" android:onClick="onClickMethod" android:text="使用onclick属性" /> <Button android:id="@+id/button5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/button4" android:text="使用View.OnClickListener方法" /> <Button android:id="@+id/button6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/button5" android:text="使用按钮的OnClickListener" />
public class MainActivity extends Activity implements View.OnClickListener { <span style="white-space:pre"> </span>bt5 = (Button) findViewById(R.id.button5); bt6 = (Button) findViewById(R.id.button6); bt5.setOnClickListener(this); bt6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "使用按钮的OnClickListener", Toast.LENGTH_SHORT).show(); } }); } public void onClickMethod(View v) { Toast.makeText(this, "使用onclick属性", Toast.LENGTH_SHORT).show(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button5: Toast.makeText(this, "使用View.OnClickListener方法", Toast.LENGTH_SHORT).show(); break; default: break; } }
相关文章推荐
- Ubuntu 14.04 桌面版 安装 JDK 7.0
- [刷题]Data Stream Median
- APP的启动页
- LeetCode之Intersection of Two Linked Lists
- 83 XML数据基本概念
- Android Tween Animation
- [Leetcode] Number of 1 Bits 关于位操作的思考
- php CLI 有用的命令
- C++函数返回多个参数
- sql server 2005 express 工具 失败
- shell脚本里的if语句学习
- 一个合格的程序员应该读过哪些书。
- 【DP】HDOJ 5426 Rikka with Game
- Linux常用工具系列 ------- yum
- android_文件下载
- C++中的inline函数
- 在Hadoop1.2.1分布式集群环境下安装hive0.12
- 分布式配置管理平台XXL-CONF
- hadoop mapreduce join代码示例及讲解
- 每个Android开发者应该知道的6个SDK和API