一、依照向导创建一个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意图传參数(四)的更多相关文章

  1. Android Api 检查參数状态Api

    转载请注明出处:http://blog.csdn.net/droyon/article/details/39938677 在进行Android应用程序开发中,android提供了一个非常好的工具类,来 ...

  2. 【Android 应用开发】Activity 状态保存 OnSaveInstanceState參数解析

    作者 : 韩曙亮 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/38297083 一. 相关方法简单介绍 1. 状态保存方法演示 ...

  3. android soundpool 參数说明

    SoundPool 类的构造函数例如以下: SoundPool(int maxStreams, int streamType, int srcQuality) 作用:实例化一个SoundPool 实例 ...

  4. Android 布局学习之——Layout(布局)具体解释二(常见布局和布局參数)

     [Android布局学习系列]   1.Android 布局学习之--Layout(布局)具体解释一   2.Android 布局学习之--Layout(布局)具体解释二(常见布局和布局參数)   ...

  5. Android 线性布局(LinearLayout)相关官方文档 - 布局參数部分

    Android 线性布局(LinearLayout)相关官方文档 - 布局參数部分 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...

  6. android 随手记之文件+參数上传请求

    第一步:须要两个jar的支持,稍后以下给会出下载地址. 第二步:建立一个project 以下贴出最基本的代码 package com.example.testpaizhao; import java. ...

  7. Fragment进阶(四)-----&gt;參数传递3种写法

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...

  8. android选择图片或拍照图片上传到server(包含上传參数)

    在9ria论坛看到的.还没測试,先Mark与大家分享一下. 近期要搞一个项目,须要上传相冊和拍照的图片.不负所望,最终完毕了! 只是须要说明一下,事实上网上非常多教程拍照的图片.都是缩略图不是非常清晰 ...

  9. android 利用cmdline,将參数从preloader传递到kernel

    以定义參数 cus_param 为例.int型变量. 1. Preloader部分 Platform.h(mediatek\platform\[$platform]\preloader\src\dri ...

随机推荐

  1. C#斐波那契数列递归算法

    public static int Foo(int i)        {            if (i < 3)            {                return 1; ...

  2. jQuery 首页搜索区域模块随页面滑动而变化

    /*搜索区块的颜色变化*/ function search(){ var searchBox = document.querySelector('.m_head'); var bannerBox = ...

  3. qrcode.js扫码邀请

    //js引用部分<script src="../qrcode.js" type="text/javascript"></script> ...

  4. 51nod 1021 石子归并 - 区间dp(经典)

    题目地址:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1021 经典区间dp,dp[i][j] 表示将从 i 到 j 堆 ...

  5. Sql语句的一些事(二)

    与sql语句的书写顺序并不是一样的,而是按照下面的顺序来执行 from--where--group by--having--select--order by, from:需要从哪个数据表检索数据 wh ...

  6. [Python3网络爬虫开发实战] 1.2.2-Selenium的安装

    Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作.对于一些JavaScript渲染的页面来说,这种抓取方式非常有效.下面我们来看看Selenium的安装 ...

  7. 【笔记】搭建OpenWrt编译环境

    参考书目<B智能路由开发指南> 目标:搭建一个OpenWrt编译环境,可以同时在家里和公司使用. [2018-09-13] 刚开始想用自己的电脑共享远程桌面,但不知道什么原因搞不定,所以干 ...

  8. tomcat时间与系统时间不一致问题

    我在部署应用到centos系统上的tomcat服务器中运行,发现操作系统的时间和tomcat中的访问日志的时间与系统时间不一致,但是查看当前操作系统的时区也是CST时区(中国标准时区). 查看系统的时 ...

  9. uva 327 - Evaluating Simple C Expressions

     Evaluating Simple C Expressions  The task in this problem is to evaluate a sequence of simple C exp ...

  10. mac 解决mysql启动不了

    mac升级了mysql,没有替换原来的链接的情况下, 启动mysql restart 会失败 解决方法,找到mysql真正的安装目录 mysql.server start