有关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函数: ...
随机推荐
- Spring Boot 快速入门(Eclipse)
步骤一:关于版本(前期工作) JDK 1.8 maven 3.5 配置环境变量: 步骤二:创建项目 首先新建个maven项目(SpringBoot 应用,本质上是一个Java 程序,其采用的风格是 m ...
- web.xml上监听器作用
<!--Spring ApplicationContext 载入 --> <listener> <listener-class>org.springframewor ...
- flume-ng源码阅读memory-channel(原创)
org.apache.flume.channel.MemoryChannel类是Flume-NG的memory-channel. private LinkedBlockingDeque<Even ...
- python 之Tornado
一.Tomado Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webap ...
- HTTP Status 500 - com.opensymphony.xwork2.ActionSupport.toAddPage()
使用struts2过程中碰到以下错误 HTTP Status 500 - com.opensymphony.xwork2.ActionSupport.toAddPage() type Exceptio ...
- HTML5 地理定位 【来自百度应用分享平台】
百度给的地图API接口相当完善,复制过来一下,以后备用 基本使用方法: <!--引入百度地图API--> <scriptsrc="http://api.map.baidu. ...
- linux中的kill命令
一. 定义 kill命令用来删除执行中的程序或工作.kill可将指定的信息送至程序.预设的信息为SIGTERM(15),可将指定程序终止.若仍无法终止该程序,可使用SIGKILL(9)信息尝试强制删除 ...
- linux下{}的用法
在touch {a,b}.txt时,同时创建了a.txt,b.txt两个文件 而touch {1..10}.txt,同时创建了10个txt文件,从1.txt到10.txt 在linux通配符中,{n, ...
- (CSharp)克隆控件事件
// https://stackoverflow.com/questions/6055038/how-to-clone-control-event-handlers-at-run-time // &q ...
- input type=file 怎么样调取用户手机照相机
input 有个属性accept="image/*" 这样就可以了,同时在网上看到了其他答案,试了下没啥效果.写记录下来 如下: 使用input:file标签, 去调用系统默认相机 ...