有关Botton的用法(一)
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here"
android:onClick="doSomething"//用来设置onClick时MainActivity中调用的函数
android:id="@+id/button" />
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void doSomething(View view){
Log.e("MainActivity","Clicked");
}
点击button时 call doSomething();
如果有多个Button,则通过下面两种方式做出不同的响应:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here"
android:onClick="doSth1"
android:id="@+id/button" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
android:onClick="doSth2"//这两调的同一个函数doSth2()
android:id="@+id/button2" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3"
android:onClick="doSth2"//这两调的同一个函数doSth2()
android:id="@+id/button3" />
public void doSth1(View view){
Log.e("MainActivity", "Clicked1");
}
public void doSth2(View view){
if(view.getId()==R.id.button2)
Log.e("MainActivity","Clicked2");
if(view.getId()==R.id.button3)
Log.e("MainActivity","Clicked3");
}
如上,在doSth2()中通过view.getId()来获取不同的值,注意@+id/button3和R.id.button3是分别在xml和java中对同一个整数值的描述
有关Botton的用法(一)的更多相关文章
- 有关Botton的用法(二)
关于设置listener监听onClicked事件的步骤分析 Steps: 1.tell android you are interested in listening to a button cli ...
- RegisterStartupScript和RegisterClientScriptBlock的用法
RegisterStartupScript和RegisterClientScriptBlock的用法 RegisterStartupScript(key, script) RegisterClient ...
- CSS3 clip-path 用法介绍
一.基本概念 刷新 QQ 空间动态时,发现一则广告,随着用户上下滑动动态列表,就会自动切换广告图片,这样的效果对移动端本就不大的屏幕来说,无疑是很精妙的考虑,这样的效果是怎么实现的呢? 你可以点击这里 ...
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
- [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...
随机推荐
- Google maps api demo 2
demo /** * @fileoverview Sample showing capturing a KML file click * and displaying the contents in ...
- linux 分析进程占用CPU过高
重点是查看进程的线程中,哪个线程占用cpu过高,然后用gdb附加到进程,调试线程,看是否有死循环或者死锁等问题,步骤如下: 1 先用ps + grep找出该死的进程pid,比如 1706 2 top ...
- java-四则运算-四
题目要求:查找数组连成环形的和最大的连续子数组 实验代码: package zuoYe; import java.util.Scanner; public class MaxSubArray { pu ...
- JAVA 泛型意淫之旅(二)
编译器如何处理泛型 泛型类编译后长什么样? 接上文,JAVA 泛型意淫之旅1,成功迎娶白富美后,终于迎来了最振奋人心的一刻:造娃!造男娃还是造女娃?对于我们程序猿来说,谁还在乎是男娃女娃,只要是自己的 ...
- 使用Mybatis连接数据库时报错:org.apache.ibatis.exceptions.PersistenceException: ### Error updating database.
我的原因是字段名写错了,去数据库中复制字段名再运行就成功了.
- 使用mybatis如果类属性名和数据库中的属性名不一样取值就会为null
使用mybatis时如果类属性名和数据库中的属性名不一样取值就会为null 这是不能再去改变javabean中的属性,只能改变sql语句.语句如下所示: <select id="sel ...
- srs部署到ubuntu 18.04 server
srs.txt ubuntu 18.04 安装 srs 1. 上传srs_40.7z和h2ws.7z到linux服务器,然后远程ssh连接 (假设登陆用户名是bob,linux服务器ip是192.16 ...
- 51nod 1119 组合数,逆元
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119 1119 机器人走方格 V2 基准时间限制:1 秒 空间限制:13 ...
- Linux系列—策略路由、ip rule、ip route
早期在管理Linux系统的网络时,常使用ifconfig及route之类的命令,不过如果你准备开始使用Linux强大的基于策略的路由机制,那么,就请不要使用这类工具了,因为这类工具根本无法用于功能强大 ...
- DCGAN、WGAN、WGAN-GP、LSGAN、BEGAN原理总结及对比
DCGAN.WGAN.WGAN-GP.LSGAN.BEGAN原理总结及对比 from:https://blog.csdn.net/qq_25737169/article/details/7885778 ...