Intent传值

来源:未知 责任编辑:智问网络 发表时间:2013-10-07 00:58 点击:

EditText et = (EditText)findViewById(R.id.etName);//定义的文本框。

String aa = et.getText().toString();//获取文本框内容。

Intent intent = new Intent();

intent.setClass(helloworld.this,android2.class);//helloworld.class为Activity,android2.class为Activity。

intent.putExtra("name", "传值测试!");//设置传递内容。

startActivity(intent);//跳转。

finish();//关闭当前Activity。

第一种写法,用于批量添加数据到Intent:
Intent intent = new Intent();
Bundle bundle = new Bundle();//该类用作携带数据
bundle.putString("name", "学习android");
intent.putExtras(bundle);//为意图追加额外的数据,意图原来已经具有的数据不会丢失,但key同名的数据会被替换
第二种写法:这种写法的作用等价于上面的写法,只不过这种写法是把数据一个个地添加进Intent,这种写法使用起来比较方便,而且只需要编写少量的代码。
Intent intent = new Intent();
intent.putExtra("name", "学习android");

在android2的onCreate方法中取值

【取值方法:String test= (String)(this.getIntent().getExtras().getString("name"));】

 
 


作者:kevinvane

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • cocos2d-x学习笔记(19)--label 、label atlas
      • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
      • Cocos2d-x学习(一):HelloWorld
      • cocos2dx在xcode下开发,编译到android上(2)
      • cocos2d 设置屏幕默认方向
      • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
      • Cocos2d-x 2.0 之 Actions “三板斧” 之一
      • cocos2d-x学习笔记(18)--游戏打包(windows平台)
      • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1