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 ...
随机推荐
- 迅为嵌入式开发板iTOP-6818开发板八核Cortex-A53架构,满足各种产品需求
性价比更高 内存:1G(可选2G);存储:16G;4418:四核 Cortex-A9;6818:八核Cortex-A53. 功能更强 板载4G(全网通),GPS,WIFI,千兆以太网,重力加速度计等, ...
- [转帖]4412开发板/4418开发板Android4.4.4实现ble功能
本文转自迅为论坛:http://bbs.topeetboard.com ①.4418开发板实现ble功能方法: 在4418/android/device/nexell/drone2/device.mk ...
- 关于TreeView控件的TreeNodeCheckChanged事件无法回发处理
1.在后台设置属性 TreeView1.Attributes.Add("onclick", "postBackByObject()"); 2.在前台页面中间添加 ...
- Django中使用多线程发送邮件
1.settings.py 增加Email设置 #mail EMAIL_HOST = ‘smtp.gmail.com’ #邮件smtp服务器 EMAIL_POR ...
- 第2节 mapreduce深入学习:12、reducetask运行机制(多看几遍)
ReduceTask的运行的整个过程 背下来1.启动线程到mapTask那里去拷贝数据,拉取属于每一个reducetask自己内部的数据2.数据的合并,拉取过来的数据进行合并,合并的过程,有可能在内存 ...
- python 3计算KL散度(KL Divergence)
KL DivergenceKL( Kullback–Leibler) Divergence中文译作KL散度,从信息论角度来讲,这个指标就是信息增益(Information Gain)或相对熵(Rela ...
- Dijkstra+set堆优化局部模板
这是某天2018-10-25写的某题(P1613-luogu)的局部代码,目的是方便自己记忆一些细节,所以这里不过多赘述算法原理或题目 邻接矩阵mapp表示有向图 struct ELE { int i ...
- kafka 服务端消费者和生产者的配置
在kafka的安装目录下,config目录下有个名字叫做producer.properties的配置文件 #指定kafka节点列表,用于获取metadata,不必全部指定 #需要kafka的服务器地址 ...
- js 技巧 (六)弹窗代码汇总
弹窗代码汇总 [0.超完美弹窗代码] 功能:5小时弹一次+背后弹出+自动适应不同分辩率+准全屏显示 代码: <script> function openwin(){ window.open ...
- CIFAR100与VGG13实战
目录 CIFAR100 13 Layers cafar100_train CIFAR100 13 Layers cafar100_train import tensorflow as tf from ...