intent.putExtra()方法参数详解
【开篇骂几句:fuck】
1.扯淡intent.putExtra()怎么使用?
2.胡说intent.putExtra();
【扯淡:其实你在问它怎么用的时候,你要明白,你知道不知道这是个什么东东,有必要问吗?有?我猜你已经知道它的基本概念了,它是用来传参数的对不对,是的,就这么简单。但你仍然在网上百度它怎么用,我不理解你为啥要这么做,哦,我又猜到了,我猜啊,你是不知道他的具体参数是怎么个用吧,对了,问题的核心来了,所有安卓开发中的问题都是方法参数的问题】
【putExtra("A",B)中,AB为键值对,第一个参数为键名,第二个参数为键对应的值。顺便提一下,如果想取出Intent对象中的这些值,需要在你的另一个Activity中用getXXXXXExtra方法,注意需要使用对应类型的方法,参数为键名】
要不我举个例子吧,,大家注意注释的地方哈,源码在下面。
来建第一个Activity:MyIntent
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
public class MyIntent extends Activity { /*声明控件对象*/ private EditText et1, et2; private Button bt; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /*取得控件对象*/ et1 = (EditText) findViewById(R.id.et1); et2 = (EditText) findViewById(R.id.et2); bt = (Button) findViewById(R.id.bt); /*为按钮绑定监听器*/ bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { /*取得输入框中的内容*/ String et1Str = et1.getText().toString(); String et2Str = et2.getText().toString(); //创建Intent对象,参数分别为上下文,要跳转的Activity类 Intent intent = new Intent(MyIntent.this, SecondActivity.class); //将要传递的值附加到Intent对象 intent.putExtra("et1", et1Str); intent.putExtra("et2", et2Str); //启动该Intent对象,实现跳转 startActivity(intent); } }); }} |
再建第二个Activity:SecondActivity
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
public class SecondActivity extends Activity{ //声明TextView对象 private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); //取得TextView对象 tv = (TextView) findViewById(R.id.tv); //取得启动该Activity的Intent对象 Intent intent =getIntent(); /*取出Intent中附加的数据*/ String first = intent.getStringExtra("et1"); String second = intent.getStringExtra("et2"); //计算得到结果 int result = Integer.parseInt(first) + Integer.parseInt(second); //设置TextView显示的文本 tv.setText("计算结果为:"+String.valueOf(result)); } } |
intent.putExtra()方法参数详解的更多相关文章
- php课程---Windows.open()方法参数详解
Window.open()方法参数详解 1, 最基本的弹出窗口代码 window.open('page.html'); 2, 经过设置后的弹出窗口 window.open('page.html ...
- Window.open()方法参数详解
Window.open()方法参数详解 1, 最基本的弹出窗口代码 window.open('page.html'); 2, 经过设置后的弹出窗口 window.open('page.html ...
- ajax方法参数详解与$.each()和jquery里面each方法的区别
JQuery中$.ajax()方法参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为g ...
- JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- JQuery中$.ajax()方法参数详解 及 async属性说明
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- JQuery中$.ajax()方法参数详解(转载)
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- $.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- 转:JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- (转)JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
随机推荐
- JSON.parse() JSON.stringify() eval() jQuery.parseJSON() 的区别
http://www.jb51.net/article/81880.htm : jQuery.parseJSON(jsonString) : 将格式完好的JSON字符串转为与之对应的Java ...
- 如何使用Java、Servlet创建二维码
归功于智能手机,QR码逐渐成为主流,它们正变得越来越有用.从候车亭.产品包装.家装卖场.汽车到很多网站,都在自己的网页集成QR码,让人们快速找到它们.随着智能手机的用户量日益增长,二维码的使用正在呈指 ...
- CodeForces 702E Analysis of Pathes in Functional Graph
倍增预处理. 先看一下这张图的结构,因为出度都是$1$,所以路径是唯一的,又因为每个点都有出度,所以必然有环,也就是一直可以走下去. 接下来我们需要记录一些值便于询问: 设$t[i][j]$表示从$i ...
- hdu1010
#include <stdio.h>#include <string.h>#include <math.h> int n,m,t;char map[10][10]; ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 26269: illegal multibyte sequence
解决方法参见下面的链接: http://blog.csdn.net/jim7424994/article/details/22675759
- Linux安全检测常用方法
一. 系统状态备份 主要是网络.服务.端口.进程等状态信息的备份工作 系统服务备份: chkconfig --list > services.log 进程备份: ps -ef > ps.l ...
- C#字符串转INT
Convent.ToInt32(string ) 可以转化字符串 其他 * .tostring(); (int ) char //强制类型转换 不能转化字符串
- c# socket传输struct类型
data结构体类型 public struct datas { public string test1; public string test2; } //socket服务器端 publi ...
- Java IO 过滤流 BufferedInput/OutputStream
Java IO 过滤流 BufferedInput/OutputStream @author ixenos 概念 BufferedInput/OutputStream是实现缓存的过滤流,他们分别是Fi ...
- hdu_2825_Wireless Password(AC自动机+状压DP)
题目链接:hdu_2825_Wireless Password 题意: 给你m个串,问长度为n至少含k个串的字符串有多少个 题解: 设dp[i][j][k]表示考虑到长度为i,第j个自动机的节点,含有 ...