首先我们需要知道Intent这个东西是用来干什么的:
intent主要可以看着是一个能够在两个Activity之间传输数据的这么一个对象,那么他的具体用法怎么用啊
我们下来就来看看这个例子吧:
package demo.jsj; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Activity03 extends Activity { private EditText factorOne; private EditText factorTwo; private TextView symbol; private Button calculate; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //根据控件的Id取得控件的对象(通过布局文件进行获取) factorOne = (EditText)this.findViewById(R.id.factorOne); factorTwo = (EditText)this.findViewById(R.id.factorTwo); symbol = (TextView)this.findViewById(R.id.symbol); calculate = (Button)findViewById(R.id.calculate); symbol.setText(R.string.symbol); calculate.setText(R.string.caloulate); calculate.setOnClickListener(new ClaculateListener()); } //添加菜单 @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(0,1,1,R.string.out);//第二个参数为ID menu.add(0,2,2,R.string.about); return super.onCreateOptionsMenu(menu); } //设置菜单的操作 @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId() == 1){ finish(); } return super.onOptionsItemSelected(item); } class ClaculateListener implements OnClickListener{ @Override public void onClick(View v) { //取得两个控件的值 String factorOneStr = factorOne.getText().toString(); String factorTwoStr = factorTwo.getText().toString(); Intent intent = new Intent(); intent.putExtra("one", factorOneStr); intent.putExtra("two", factorTwoStr); intent.setClass(Activity03.this, ResultActivity.class); Activity03.this.startActivity(intent); } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:id="@+id/factorOne" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/symbol" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:id="@+id/factorTwo" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/calculate" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
发表评论
-
Android临时数据缓存方法
2011-07-22 22:58 1968学习Android的朋友欢迎加入:群 59324839(QQ) ... -
ContentProvider内容提供者
2011-07-22 22:58 1292学习Android的朋友欢迎加入:群 59324839(Q ... -
android网络
2011-07-22 22:57 1070学习Android的朋友欢迎加入:群 59324839(Q ... -
SQLite数据库
2011-07-22 22:55 841学习Android的朋友欢迎加入:群 59324839(QQ) ... -
Android Xml解析
2011-07-22 22:53 928学习Android的朋友欢迎加入:群 59324839(Q ... -
Android SharedPreferences
2011-07-22 22:53 1044学习Android的朋友欢迎加入:群 59324839(Q ... -
Android XMl写入
2011-07-22 22:51 1126学习Android的朋友欢迎加入:群 59324839(Q ... -
Android 权限配置
2011-07-22 22:51 1448学习Android的朋友欢迎加入:群 59324839(Q ... -
Android 文件操作
2011-07-22 22:45 891学习Android的朋友欢迎加入:群 59324839(QQ) ... -
Android Dialog的使用
2011-07-22 22:44 1021学习Android的朋友欢迎加入:群 59324839(QQ) ... -
android 技术讨论群(QQ)
2011-07-04 22:18 412android 学习群; 可供广大群从参加! 初学者欢 ... -
SQL判断一个表在系统中是否存在
2011-07-03 18:49 1574/** * 判断某张表是否存在 * @ ... -
android 对话框应用
2011-06-28 00:21 894啥都别说了,看效果吧! new AlertDialog ... -
ContentProvider
2011-06-27 21:13 3458在 Android中,对于数据的存贮,有几种方式,有文件方式 ... -
android 权限大全
2011-06-14 00:19 882java.net.SocketException: Perm ... -
android GUI线程安全
2011-06-11 18:28 1289Activity:运行于主线程。因Android的GUI是 ... -
android 下载程序
2011-06-10 00:34 1047HttpDownloader 文件: package zho ... -
android SQLite使用
2011-06-10 00:33 1418package zhou.demo.sql; impor ... -
android Handler and progress
2011-06-10 00:31 812package zhou.demo; import andr ... -
android Handler使用
2011-06-10 00:31 898package zhou.demo; import andr ...
相关推荐
Android activity、菜单及dialog、列表等常见UI源码,下面依次介绍各目录里的功能演示: activity_intent:activity的跳转1.不带返回值的跳转2.带返回值的跳转,intent的简单介绍。Bundle的简单介绍。 dialog...
主要介绍了android基础总结篇之九:Intent应用详解,有需要的可以了解一下。
4.5 创建和使用菜单 4.5.1 Android菜单系统简介 4.5.2 定义活动的菜单 4.5.3 动态更新菜单项 4.5.4 处理菜单选择 4.5.5 子菜单和上下文菜单 4.5.6 To-Do List示例续 4.6 小结 第5章 Intent、广播接收器、 Adapter和...
作为使用androidsdk构建这些应用程序的实用指南书籍,《android高级编程》从始至终穿插了一系列示例项目,每个项目都引入android的新功能和新技术,以助您达到最圆满的学习效果。书中介绍android的所有基本功能,并...
第6章 Android菜单和布局设计 6.1 菜单(Menu) 6.1.1 上下文菜单(ContextMenu) 6.1.2 选项菜单(OptionsMenu) 6.1.3 基于XML的菜单结构 6.2 界面布局设计 6.2.1 基于XML的布局设计 6.2.2 线性布局(LinearLayout...
1.5 使用Android SDK开发最终用户应用程序 1.5.1 Android模拟器 1.5.2 Android UI 1.5.3 Android基础组件 1.5.4 高级UI概念 1.5.5 Android Service组件 1.5.6 Android媒体和电话组件 1.5.7 ...
主要介绍了Android实现菜单关联activity的方法,涉及Android使用Intent实现菜单关联activity相关操作技巧,需要的朋友可以参考下
本文实例为大家分享了Android圆形菜单的使用方法,供大家参考,具体内容如下 MainActivity.java代码: package siso.handlerdemo; import android.app.NotificationManager; import android.content.Intent; import ...
5.1.3 使用Intent Filter作为插件和扩展 5.1.4 使用Intent来广播事件 5.2 Adapter简介 5.2.1 Android提供的部分Adapter简介 5.2.2 使用Adapter绑定数据 5.3 使用Internet资源 5.3.1 连接到Internet资源 5.3.2 利用...
第5章 使用Intent和IntentFilter 第5章 进行通信 196 5.1 Intent对象详解 197 5.1.1 使用Intent启动系统组件 197 5.2 Intent的属性及intent-filter 配置 198 5.2.1 Component属性 198 5.2.2 Action...
作为使用AndroidSDK构建这些应用程序的实用指南书籍,《Android高级编程》从始至终穿插了一系列示例项目,每个项目都引入Android的新功能和新技术,以助您达到最圆满的学习效果。书中介绍Android的所有基本功能,并...
作为使用AndroidSDK构建这些应用程序的实用指南书籍,《Android高级编程》从始至终穿插了一系列示例项目,每个项目都引入Android的新功能和新技术,以助您达到最圆满的学习效果。书中介绍Android的所有基本功能,并...
本文实例为大家分享了Intent如何实现一个简单的记事本功能的演示过程,供大家参考,具体内容如下 1、运行截图 单击右上角【…】会弹出【添加】菜单项,长按某条记录会弹出快捷菜单【删除】项。 2、主要设计步骤 (1...
是 Android 上实现类似 Facebook 和 Path 2.0 滑动式菜单的组件。 12、AsyncImageView 是 Android 上的一个异步从网络上获取图片并进行浏览的开源组件,可自动在本地进行缓存。该项目是 GreenDroid 的一部分。 13...
要使用这个必须在配置文件中加入<uses-permission id="Android.permission.CALL_PHONE" /> 发送SMS/MMS 调用发送短信的程序 1. Intent it = new Intent(Intent.ACTION_VIEW); 2. it.putExtra("sms_body", "The ...
8.1.1使用Intent连接Activity 8.1.2 Activity的生命周期 …… 第9章Android中的数据存储 第10章绚丽的多媒体技术 第11章Android网上冲浪 第12章Android地图服务 第4篇项目案例开发 第13章联系人助手 第14章个人轨迹...
第十六讲:菜单 Android Menu 第十七讲:对话框 Android Dialog 第十八讲:Android SharedPreferences和File 第十九讲:Android Notification的使用入门 第二十讲:Content Provider 使用入门 第二十一讲...
第7章 良好的学习开端——Android基本组件介绍之Android应用的灵魂——Intent和Activity介绍与实例 第7章 良好的学习开端——Android基本组件介绍之用好列表,做好程序——列表(ListView)介绍与实例 第7章 良好的...