android意图传參数(四)
一、依照向导创建一个project,layout的activity_main.xml文件内容例如以下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
tools:context=".MainActivity" > <Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="意向传參数測试"
/> </RelativeLayout>
1)android:layout_width="match_parent" :谷歌把fill_parent改成了与实际效果更符合的match_parent,表示塞满容器,塞的意思就是有多少空间,占用多少空间
2)android:layout_height="wrap_content" :设置为wrap_content将完整显示其内部的文本和图像。布局元素将依据内容更改大小。
设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。
3)android:text :设置button的显示值
二、在Main函数做意向传參跳转
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
<span style="color:#ff0000;"> Intent intent = new Intent(MainActivity.this,OtherActivity.class);
intent.putExtra("name", "Deng");
intent.putExtra("age", 23);
startActivity(intent);</span>
}
});
}
通过startActivity方法启动
三、新建一个other.xml 和 OtherActivity.class
<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/> </LinearLayout>
public class OtherActivity extends Activity {
private TextView textview;
public OtherActivity(){
}
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
textview = (TextView)this.findViewById(R.id.msg);
<span style="color:#ff0000;">Intent intent = getIntent();</span>
<span style="color:#ff0000;">String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 0);</span>
textview.setText("name"+name+";"+"age"+age);
}
}
记得重写onCreate方法以及设置setContentView布局
四、最后在文件AndroidManifest.xml加入一个activity标签
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.android_intent.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<span style="color:#ff0000;"> <activity
android:name = ".OtherActivity"
/></span>
</application>
android意图传參数(四)的更多相关文章
- Android Api 检查參数状态Api
转载请注明出处:http://blog.csdn.net/droyon/article/details/39938677 在进行Android应用程序开发中,android提供了一个非常好的工具类,来 ...
- 【Android 应用开发】Activity 状态保存 OnSaveInstanceState參数解析
作者 : 韩曙亮 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/38297083 一. 相关方法简单介绍 1. 状态保存方法演示 ...
- android soundpool 參数说明
SoundPool 类的构造函数例如以下: SoundPool(int maxStreams, int streamType, int srcQuality) 作用:实例化一个SoundPool 实例 ...
- Android 布局学习之——Layout(布局)具体解释二(常见布局和布局參数)
[Android布局学习系列] 1.Android 布局学习之--Layout(布局)具体解释一 2.Android 布局学习之--Layout(布局)具体解释二(常见布局和布局參数) ...
- Android 线性布局(LinearLayout)相关官方文档 - 布局參数部分
Android 线性布局(LinearLayout)相关官方文档 - 布局參数部分 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...
- android 随手记之文件+參数上传请求
第一步:须要两个jar的支持,稍后以下给会出下载地址. 第二步:建立一个project 以下贴出最基本的代码 package com.example.testpaizhao; import java. ...
- Fragment进阶(四)----->參数传递3种写法
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- android选择图片或拍照图片上传到server(包含上传參数)
在9ria论坛看到的.还没測试,先Mark与大家分享一下. 近期要搞一个项目,须要上传相冊和拍照的图片.不负所望,最终完毕了! 只是须要说明一下,事实上网上非常多教程拍照的图片.都是缩略图不是非常清晰 ...
- android 利用cmdline,将參数从preloader传递到kernel
以定义參数 cus_param 为例.int型变量. 1. Preloader部分 Platform.h(mediatek\platform\[$platform]\preloader\src\dri ...
随机推荐
- [分享] IMX6嵌入式开发板linux QT挂载U盘及TF卡
本文转自迅为开发板:http://www.topeetboard.com 开发平台:iMX6开发板 linux QT 系统下挂载 u 盘如下图所示,qt 启动之后,在超级终端中使用命令“mknod / ...
- 迅为嵌入式开发板iTOP-6818开发板八核Cortex-A53架构,满足各种产品需求
性价比更高 内存:1G(可选2G);存储:16G;4418:四核 Cortex-A9;6818:八核Cortex-A53. 功能更强 板载4G(全网通),GPS,WIFI,千兆以太网,重力加速度计等, ...
- Servlet相关的几种中文乱码问题
Servlet相关的几种中文乱码问题浏览器调用jsp,html等页面中文显示乱码使得文件本身以utf-8字符集编辑保存 让浏览器浏览器以utf-8字符集解析 在浏览器中右键选择编码格式为utf-8: ...
- 输入和输出(IO流)
File类的常用方法: File对象的创建和部分方法使用: File file =new File("file\\我是文本.txt"); System.out.println(&q ...
- eclipse包分层
方法很简单,如下图所示: 1.点击项目栏窗口的右上角的倒三角 2.选择Pachage Presentation(包呈现) 3.选择Hierarchical(分层)
- Python轮换
switch_source()用于获取文本信息rewrite_source()用于将信息顺序轮换,其参数times表示要轮换多少次, def switch_source(): tmp = [] wit ...
- Python之turtle库-小猪佩奇
Python之turtle库-小猪佩奇 #!/usr/bin/env python # coding: utf-8 # Python turtle库官方文档:https://docs.python.o ...
- MySQL-----唯一索引
唯一索引: 单列唯一索引和联合唯一索引 索引是为了加速查找. 唯一索引是加了约束条件.例如主外键. 唯一索引的约束: 约束不能重复(可以为空) 主键不能重复(不能为空) 加速查找 create tab ...
- python爬虫入门01:教你在 Chrome 浏览器轻松抓包
通过 python爬虫入门:什么是爬虫,怎么玩爬虫? 我们知道了什么是爬虫 也知道了爬虫的具体流程 那么在我们要对某个网站进行爬取的时候 要对其数据进行分析 就要知道应该怎么请求 就要知道获取的数据是 ...
- NOR flash and NAND flash
(1)读写的基本单位 应用程序对NOR芯片操作以"字"为基本单位.为了方便对大容量NOR闪存的管理,通常将NOR闪存分成大小为128KB或者64KB的逻辑块,有时候块内还分成扇区. ...