【开篇骂几句: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()方法参数详解的更多相关文章

  1. php课程---Windows.open()方法参数详解

    Window.open()方法参数详解 1, 最基本的弹出窗口代码   window.open('page.html'); 2, 经过设置后的弹出窗口   window.open('page.html ...

  2. Window.open()方法参数详解

    Window.open()方法参数详解 1, 最基本的弹出窗口代码   window.open('page.html'); 2, 经过设置后的弹出窗口   window.open('page.html ...

  3. ajax方法参数详解与$.each()和jquery里面each方法的区别

    JQuery中$.ajax()方法参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为g ...

  4. JQuery中$.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  5. JQuery中$.ajax()方法参数详解 及 async属性说明

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  6. JQuery中$.ajax()方法参数详解(转载)

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  7. $.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  8. 转:JQuery中$.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  9. (转)JQuery中$.ajax()方法参数详解

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

随机推荐

  1. Python os.path模板函数

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  2. js实现搜索框响应回车键

    1.HTML页面, 注意:不要用使用form标签. Html代码 收藏代码<input type="text" name="keyword" id=&qu ...

  3. JSON.parse() JSON.stringify() eval() jQuery.parseJSON() 的区别

    http://www.jb51.net/article/81880.htm    :   jQuery.parseJSON(jsonString) : 将格式完好的JSON字符串转为与之对应的Java ...

  4. $(#form :input)与$(#form input)的区别

    相信大家都很奇怪这两者的区别 我从两个方面简单介绍下 1. $("form :input") 返回form中的所有表单对象,包括textarea.select.button等    ...

  5. linux下svn目录管理

    linux 下安装的svn目录文件: /data/svndata/winne/conf/passwd 是配置用户密码的文件路径

  6. Javaweb 第6天JDBC课程

    JDBC课程 两日大纲 ● JDBC基本操作 ● 预设语句对象 ● 自定义数据库工具类 ● JDBC批处理 ● 事务 ● 连接池 *********************************** ...

  7. Journey

    Journey 题目链接:http://codeforces.com/problemset/problem/721/C dp/记忆化搜索/拓扑排序 刚开始想到用bfs+dp,fst(然而中间有一步逻辑 ...

  8. CABasicAnimation 几种停止的回调

    一.编写一个简单的动画,使一个UIview从屏幕的左上角移动到左下角,间隔时间3S // // ViewController.m // CAAnimationTest // // Created by ...

  9. aspnet5安装ef7备忘

    1.安装kvm 首先,你需要以管理员权限打开cmd,执行如下的脚本: @powershell -NoProfile -ExecutionPolicy unrestricted -Command &qu ...

  10. Multidimensional Arrays

    Overview An array having more than two dimensions is called a multidimensional array in the MATLAB® ...