To respond to the button's on-click event, open the activity_main.xml layout file and add the android:onClick attribute to the <Button> element:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send"
    android:onClick="sendMessage"/>
The android:onClick attribute’s value, "sendMessage", is the name of a method in your activity that the system calls when the user clicks the button.

Open the MainActivity class (located in the project's src/ directory) and add the corresponding method:

/** Called when the user clicks the Send button */
publicvoid sendMessage(View view){
    // Do something in response to button
}

This requires that you import the View class:

import android.view.View;

Tip: In Eclipse, press Ctrl + Shift + O to import missing classes (Cmd + Shift + O on Mac).

In order for the system to match this method to the method name given to android:onClick, the signature must be exactly as shown. Specifically, the method must:

  • Be public
  • Have a void return value
  • Have a View as the only parameter (this will be the View that was clicked)

Next, you’ll fill in this method to read the contents of the text field and deliver that text to another activity.

The First Android App----Starting Another Activity的更多相关文章

  1. Android App组件之Activity

    Android App组件之Activity 1 activit介绍 Activities 是Android的四大组件之一,其余三大组件是service.broadcast和content provi ...

  2. How To Use Proguard in Android APP

    在Android开发完成即将发布给用户使用时,还有最后重要的一步:代码混淆,这时候,Proguard就派上用场了,大家谁也不想辛辛苦苦写的代码太容易被别人反编译过来,而Proguard就是帮我们实现这 ...

  3. MVP应用在android app上

    使用MVP模式来解耦activity中业务代码和界面代码.在activity中,将其中的业务抽象到presenter层:将其中的界面代码抽象到View层. MVP模式: 一个软件被划分成三层,View ...

  4. 命令行下使用javah命令生成.h文件,出现“错误: 无法访问android.app.Activity 找不到android.app.Activity的类文件”的解决方法

    在学习NDK中,当我在项目的bin/classes目录下使用javah命令生成头文件时,出现了“错误: 无法访问android.app.Activity 找不到android.app.Activity ...

  5. 使用javah生成.h文件, 出现无法访问android.app,Activity的错误的解决

    在工程ndk22/bin/classes中 运行javah  com.cn.ndk22.Ndk22.Activity ,出现了.h文件 我在bin/classes目录中 ,就是无法访问, : 错误:无 ...

  6. javah编译class文件找不到android.app.Activity的类文件

    在android工程的根目录使用javah生成jni 头文件时候,报找不到android.app.Activity的类文件错误. 无法访问android.app.Activity是说明没有引入andr ...

  7. android.app.Activity 的介绍

    发现当前Android的资料不是非常多,并且对于Activity的介绍也非常少.所以把官方文档的android.app.Activity的介绍翻译了一下,增加了一些自己的理解.各位假设认为我自己理解的 ...

  8. appium简明教程(9)——如何获取android app的Activity

    有时候在appium的Desired Capabilities中需要指定被测app的appActivity,下面的方法可能会对你有所帮助. 方法一 如有你有待测项目的源码,那么直接查看源码就好.如果没 ...

  9. Android app启动activity并调用onCreate()方法时都默默地干了什么?

    Android app启动activity并调用onCreate() 方法时都默默地干了什么?   在AndroidManifest.xml文件中的<intent-filter>元素中有这 ...

  10. 如何找到Android app启动activity和页面元素信息

    在实施app自动化的时候,我们需要知道app 的启动activity和页面元素信息,以此启动app和定位页面元素,那么如何在没有源码的情况下找打他们呢?当然是有好的工具啦,有Android sdk自带 ...

随机推荐

  1. pyDes库 实现python的des加密

    下载及简介地址:https://twhiteman.netfirms.com/des.html 如需要在python中使用des加密,可以直接使用pyDes库加密,该库提供了CBC和ECB两种加密方式 ...

  2. 自然对数e(转)

    e表示增长的极限 e=limx→+∞ (1+1/x)^x≍2.71828 假设,一根竹子,第一天是1米,第二天长了1米,然后这根柱子的长度变成了2米.相当于 (1+1/1)^1.上面这个假设,如果仔细 ...

  3. docker 配置远程访问

    系统: centos 7 Docker version 1.12.6 yum 安装的  #yum install docker docker server在192.168.111.120上 # vim ...

  4. Eclipse安装教程

    Eclipse安装教程     (Win7_64bit + Eclipse_64bit + JDK_8u131_64bit + python2.7.8 + PyDev5.7.0插件) 适用操作系统:W ...

  5. JTopo 使用

    1. 下载JTopo js http://www.jtopo.com/download.html 2. 引入js文件,引入jtopo之前引入jQuery 3. JTopo Demo -- 圆形布局 步 ...

  6. MyBatis多对多查询

    -------------------siwuxie095                                 MyBatis 多对多查询         以订单和商品为例,即 一个订单可 ...

  7. 将tomcat做成服务

    ①修改startup.bat 在第一行前加入如下内容: SETJAVA_HOME=D:\ProgramFiles\tool\Java\jdk1.6 SETCATALINA_HOME=D:\Progra ...

  8. jsp页面遍历List<Array>与Map

    数据结构下如图所示,之前的前辈遍历方法如下,代码直接抛异常哈, <c:if test="${!empty data1}"> <c:forEach items=&q ...

  9. 全排列12 · Permutations

    无重复 [抄题]: Given a collection of numbers, return all possible permutations. For example,[1,2,3] have ...

  10. 从输入url到显示网页发生了什么

    原文链接:https://juejin.im/post/5bf23afa6fb9a049be5d1494 在浏览器中输入url到显示网页主要包含两个部分: 网络通信和页面渲染 互联网内各网络设备间的通 ...