The First Android App----Starting Another Activity
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"/>
Theandroid:onClickattribute’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 Viewas the only parameter (this will be theViewthat 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的更多相关文章
- Android App组件之Activity
		Android App组件之Activity 1 activit介绍 Activities 是Android的四大组件之一,其余三大组件是service.broadcast和content provi ... 
- How To Use Proguard in Android APP
		在Android开发完成即将发布给用户使用时,还有最后重要的一步:代码混淆,这时候,Proguard就派上用场了,大家谁也不想辛辛苦苦写的代码太容易被别人反编译过来,而Proguard就是帮我们实现这 ... 
- MVP应用在android app上
		使用MVP模式来解耦activity中业务代码和界面代码.在activity中,将其中的业务抽象到presenter层:将其中的界面代码抽象到View层. MVP模式: 一个软件被划分成三层,View ... 
- 命令行下使用javah命令生成.h文件,出现“错误: 无法访问android.app.Activity 找不到android.app.Activity的类文件”的解决方法
		在学习NDK中,当我在项目的bin/classes目录下使用javah命令生成头文件时,出现了“错误: 无法访问android.app.Activity 找不到android.app.Activity ... 
- 使用javah生成.h文件, 出现无法访问android.app,Activity的错误的解决
		在工程ndk22/bin/classes中 运行javah com.cn.ndk22.Ndk22.Activity ,出现了.h文件 我在bin/classes目录中 ,就是无法访问, : 错误:无 ... 
- javah编译class文件找不到android.app.Activity的类文件
		在android工程的根目录使用javah生成jni 头文件时候,报找不到android.app.Activity的类文件错误. 无法访问android.app.Activity是说明没有引入andr ... 
- android.app.Activity 的介绍
		发现当前Android的资料不是非常多,并且对于Activity的介绍也非常少.所以把官方文档的android.app.Activity的介绍翻译了一下,增加了一些自己的理解.各位假设认为我自己理解的 ... 
- appium简明教程(9)——如何获取android app的Activity
		有时候在appium的Desired Capabilities中需要指定被测app的appActivity,下面的方法可能会对你有所帮助. 方法一 如有你有待测项目的源码,那么直接查看源码就好.如果没 ... 
- Android app启动activity并调用onCreate()方法时都默默地干了什么?
		Android app启动activity并调用onCreate() 方法时都默默地干了什么? 在AndroidManifest.xml文件中的<intent-filter>元素中有这 ... 
- 如何找到Android app启动activity和页面元素信息
		在实施app自动化的时候,我们需要知道app 的启动activity和页面元素信息,以此启动app和定位页面元素,那么如何在没有源码的情况下找打他们呢?当然是有好的工具啦,有Android sdk自带 ... 
随机推荐
- Hadoop主要架构
			主要架构图 各部分作用 * Core:核心支持,内核代码 * MapReduce:映射数据 * HDFS:文件存储 * ZooKepper:服务器节点和进程通信的协调工具 * Pig:支持用户和Map ... 
- mysql在linux中安装问题和命令
			1. cd / 切换到 根目录. 2. cd /root 切换到根目录下的 root目录. 3. cd .. 切换到当前目录的上级目录. 4. rpm --qa mysql 查询已经安装mysql. ... 
- python mysql connector
			install pip install mysql-connector-python-rf 报错 从https://dev.mysql.com/downloads/connector/python ... 
- Nexus 按项目类型分配不同的工厂来发布不同 项目
			但是有时候,一个公司会有很多项目[crm,oa,erp]等等的项目.如果把这些项目全部都放到releases或者snapshots中的话会有点混乱.比较好的办法是,按项目来分.每个项目一个工厂:cms ... 
- 源码包的解压   .tar.gz /.tar.bz2的解压
			解压方式如下: .tar.gz 格式解压为 tar -zxvf xx.tar.gz .tar.bz2 格式解压为 tar -jxvf ... 
- 探讨 .NET 4 新增的 SortedSet 类
			http://www.cnblogs.com/WizardWu/archive/2010/06/17/1759297.html 
- 安装使用phpStudy在本机配置php运行环境
			前言: php开发的初学者,强烈推荐使用phpStudy集成环境,一方面这个的确很好用(本人电脑安装了jspStudy,可以同时调试php和jsp),另一方面呢,虽然本人是技术控,但对这些繁杂的安装部 ... 
- ios runtime简单实用(添加动态属性)
			#import "Person.h" @interface Person (PersonCategory) // 添加Person中没有的name属性 @property (n ... 
- win8.1下cocos2d-x 3.x环境搭建
			Win8.1下Cocos2d-x 3.4环境搭建 第一步: 需要下载的:(Windows 64位系统下环境搭建) Ant apache-ant-1.9.4-bin.zip NDK androi ... 
- Castle ActiveRecord学习(一)简介
			简介 来源:http://www.cnblogs.com/zxj159/p/4082987.html 一.Active Record(活动记录)模式 Active Record是业务逻辑层中(< ... 
