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 ...
 
随机推荐
- (转) 淘淘商城系列——使用FastDFS-Client客户端进行上传图片的测试
			
http://blog.csdn.net/yerenyuan_pku/article/details/72804018 不久之前,我们实现了商品的类目选择这个功能,但这只是万里长征的第一步,我们还有很 ...
 - 正则表达式,匹配查找函数(preg_match_all)flags参数对比
			
格式: int preg_match_all ( string pattern, string subject, array matches [, int flags] ) 参数 flags 选项有以 ...
 - 01XML文档结构
			
文档结构 2.1文档结构 2.1.1文档声明及字符编码 <?xml version=“1.0” encoding=“”gb2312 standalone=“yes”?> <? 告诉 ...
 - js-时间戳转字符串
			
function createTime(v){ var now = new Date(v); var yy = now.getFullYear(); //年 var mm = now.getMonth ...
 - NSFileHandle类
			
Objective-C使用NSFileHandle类对文件进行基本操作,IOS文件操作 NSFileHandle类中得方法可以对文件进行基本的读写,偏移量的操作.NSFileHandle基本步骤:1. ...
 - CentOS 7.4  源码编译安装 Redis
			
一.CentOS 7.4 源码编译安装 Redis 1.下载源码并解压 wget http://download.redis.io/releases/redis-4.0.10.tar.gz tar ...
 - mysql、MariaDB的简单操作
			
mysql的简单操作 一.查看数据库 SHOW DATABASES; 例如: MariaDB [(none)]> show databases; +--------------------+ | ...
 - mysql错误Error(1133): Can’t find any matching row in the use
			
执行插入用户语句没有问题,但是执行权限赋值的时候提示:1133 - Can't find any matching row in the user table; 解决办法:插入新的用户成功时,需要刷新 ...
 - Courses on Turbulence
			
Courses on Turbulence Table of Contents 1. Lecture 1.1. UIUC Renewable energy and turbulent environm ...
 - 集训第四周(高效算法设计)D题 (区间覆盖问题)
			
原题 UVA10020 :http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19688 经典的贪心问题,区间上贪心当然是右区间越 ...