第一步:设置sting.xml中配置Button。

<resources><string name="app_name">04Onclicks</string><string name="action_settings">Settings</string><string name="app_phone">点击按钮事件展示</string><string name="app_one">第一种</string><string name="app_two">第二种</string><string name="app_there">第三种</string><string name="app_android">第三种</string><string name="app_iphone">第四种</string>
</resources>


第二步:设置content_mian.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.jikexueyuan.a04onclicks.MainActivity"
    tools:showIn="@layout/activity_main"><TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_phone" /><Button
        android:id="@+id/bt_one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_one"/><Button
        android:id="@+id/bt_two"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_two"/><Button
        android:id="@+id/bt_there"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_there"
        android:onClick="getSoce"/><Button
        android:id="@+id/bt_android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_android"
        android:onClick="getSoce"/><Button
        android:id="@+id/bt_iphone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_iphone"
        android:onClick="getSoce"/>
</LinearLayout>

第三步:设置MainActivity.java

public void getSoce(View v){int id = v.getId();switch (id){case R.id.bt_there:System.out.println("第三种事件被点击");break;case R.id.bt_android:System.out.println("安卓");break;case R.id.bt_iphone:System.out.println("苹果");break;}}

Android开发案例Onclick点击事件switch调用分类04相关推荐

  1. Android 快捷键生成onClick()点击事件方法

    目录 首先,在xml中: 然后,将光标移到myOnclick上 最后,创建事件处理的方法 我们知道, 一般在xml中可以设置button控件的点击事件处理的方法,可以在onClick属性的设置值,这个 ...

  2. android_button onclick点击事件的5种写法

    android项目开发中经常使用button按钮的onclick点击事件来做一些操作,android onclick事件通常有这5种写法经常被使用,本文以android Toast弹窗来举例,原文转自 ...

  3. 《Android开发案例驱动教程》

    <Android开发案例驱动教程> 作者:关东升,赵志荣 Java或C++程序员转变成为Android程序员 采用案例驱动模式展开讲解知识点,即介绍案例->案例涉及技术->展开 ...

  4. Android中按钮的点击事件的四种写法

    如题,在Android中按钮的点击事件有四种写法,如下图. 界面为四个Button+一个TextView+一个ImageView activity_main布局文件如下: <?xml versi ...

  5. textview点击事件 android,Android给TextView添加点击事件的实现方法

    首先设定TextView的clickable属性为true. 可以在布局文件中进行设定,比如: android:id="@+id/phone" android:clickable= ...

  6. Android 如何判断鼠标点击事件

    Android 如何判断鼠标点击事件 参考以下的文字 http://blog.csdn.net/shanghaibao123/article/details/49494039 http://blog. ...

  7. android切换字体颜色,Android开发实现按钮点击切换背景并修改文字颜色的方法

    本文实例讲述了Android开发实现按钮点击切换背景并修改文字颜色的方法.分享给大家供大家参考,具体如下: 其实原理很简单,用到的是selector,用来设置android:background和an ...

  8. android 评论的展开功能,Android开发实现ListView点击展开收起效果示例

    本文实例讲述了Android开发实现ListView点击展开收起效果.分享给大家供大家参考,具体如下: 废话不说先上效果: 实际上这是采用一个ExpandableListView实现的 布局文件很简单 ...

  9. 2、简单的onclick点击事件

    这篇文章讲的是简单的onclick点击事件,后面会有更详细与复杂的讲解与用法. 这个代码实现的效果就是一个简单的弹窗,点击一个按钮,弹出一个alert.看代码: <button onclick= ...

最新文章

  1. 并行计算框架 Apache Hama
  2. -Objc 、 -all_load 、 -force_load
  3. 【.NET Core项目实战-统一认证平台】第十章 授权篇-客户端授权
  4. Java Servlet 编程,重定向介绍
  5. LeetCode 面试题55 二叉树的深度
  6. python3 web框架_循序渐进Python3(十二) --0--  web之框架
  7. 页面加载被延迟 Firefox将禁用对DV和OV证书的OCSP检查
  8. 第二阶段团队冲刺第九天
  9. iOS开发过程中常见错误问题及解决方案
  10. linux连同目录一起删除,linux中文件的常用操作
  11. Android的 线性布局,Android布局之LinearLayout线性布局
  12. 添加manifest解决IDirect3DDevice9::GetFrontBufferData抓屏返回失败
  13. 好用的android高清播放器,高清播放器哪个好用(推荐4款4K高清画质播放器)
  14. vue中引用BScroll监听上拉加载报错
  15. 全志V3s IIC控制器驱动分析
  16. python处理xps文件_xps/pdf/png/json转换
  17. 百度应用市场app认领操作
  18. java applet介绍,Java中的Applet介绍
  19. 图片太大上传不了怎么缩小?jpg图片压缩大小的方法
  20. 写给二线城市【Python工程师】的成长指南

热门文章

  1. 人间,除了生死,一切都不是事
  2. 3D立体字生成器【免费在线工具】
  3. R语言学习系列之本地数据获取
  4. 多个拦截器运行顺序,false 和 true 含义
  5. DSP音频软件与算法开发
  6. 数据通信与网络(五)
  7. 传输线的物理基础(三):传输线的瞬时阻抗
  8. 选了combobox里的选项后没激发change事件_35岁前多用利弊分析,35岁后要有“安全边际”...
  9. 【重读经典】《Python核心编程(第3版)》
  10. 如何下载python与安装