有关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函数: ...
随机推荐
- Docker基于容器创建镜像
docker commit -m "提交信息" -a "作者信息" imgId imgName
- CocoaPods学习系列1——安装和常规使用
CocoaPods是一个Github上的开源项目,目前已经成为iOS开发过程中标准的依赖库管理器,提供了一种对第三方类库简单优雅的集成和管理方案. 其工作原理,是将第三方类库统一管理到一个名为Pods ...
- Spring 静态注入讲解(MethodInvokingFactoryBean)
/* * Copyright (c) 2017 4PX Information Technology Co.,Ltd. All rights reserved. */package com.fpx.o ...
- glance cache
用在多个glance API server 中,对相同的image文件提供服务.该cache对用户透明. 配置文件有一个image_cache_max_size,超过的话image cache会被修剪 ...
- MFC--根据串口采集的数据借助GDI绘制曲线
根据采集到的数据绘制曲线 在串口编程中会涉及到这样一个问题,就是将采集到的数据以曲线的形式展示出来,大家自然而然会想到采用方便快捷的控件进行编程.编程周期短,完成任务快,但是真实情况来看,控件会实现很 ...
- 【scala】语法的省略
我们直到JAVA在语法方面是冗长的,但是JAVA的可读性非常好. 在Scala的语法并不像JAVA那样冗长,但是又不失可读性,我们这里记录一下常见的语法省略. 首先是我们可以省略数据类型,因为Scal ...
- null与""的区别
两者的区别与 “数字0和没有不是同一种概念”是一个道理.null是空对象,""是空字符串null可以赋值给任何对象,而""就不行了,只能赋值给字符串对象如:St ...
- LeetCode OJ :Unique Binary Search Trees II(唯一二叉搜索树)
题目如下所示:返回的结果是一个Node的Vector: Given n, generate all structurally unique BST's (binary search trees) th ...
- SpringCloud教程 | 第十二篇: 断路器监控(Hystrix Dashboard)
版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://blog.csdn.net/forezp. http://blog.csdn.net/forezp/art ...
- Python探索记(16)——Python的可变类型与不可变类型
# @Time : 2017/7/8 17:49 # @Author : 原创作者:谷哥的小弟 # @Site : 博客地址:http://blog.csdn.net/lfdfhl # @DESC : ...