zoukankan      html  css  js  c++  java
  • android之intent学习

    Intent传值

           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").toString());】

  • 相关阅读:
    Python 面向对象(初级篇)
    python中的运算符
    初识Python
    浅谈计算机
    Zeppelin interperter 模式设置总结图解2
    maven 使用错误
    TensorFlow anaconda命令备忘
    zeppelin ERROR总结
    YARN 命令总结
    Zeppelin interperter 模式设置总结图解1
  • 原文地址:https://www.cnblogs.com/hyzhou/p/3025837.html
Copyright © 2011-2022 走看看