zoukankan      html  css  js  c++  java
  • 关于Bundle传递消息

    定义引用三个组件
    EditText name = (EditText)findViewById(R.id.name);
    EditText passwd = (EditText)findViewById(R.id.passwd);
    RadioButton male = (RadioButton) findViewById(R.id.male);
    String gender = male.isChecked() ? "男 " : "女";
    Person p = new Person(name.getText().toString(), passwd
    .getText().toString(), gender);

    /***********id.getText()此方法得到相应输入框的内容

    data.putSerializable("person", p);
    "person"为可序列化数据包的key只是作为区分传送数据包的标志。
    p为传送的对象。

    利用Intent发送相关数据包,需要建立一个新的Intent的连接。
    利用Intent的putExtras(data);发送数据包。

    *******************/

    // 创建一个Bundle对象
    Bundle data = new Bundle();
    data.putSerializable("person", p);
    // 创建一个Intent
    Intent intent = new Intent(MainActivity.this,
    ResultActivity.class);

    intent.putExtras(data);
    // 启动intent对应的Activity
    startActivity(intent);


    /**************************************************************

    以上为发送数据包相关代码。下面写接受数据包以及显示数据
    ***************************************************************/
    定义三个显示文本组件
    TextView name = (TextView) findViewById(R.id.name);
    TextView passwd = (TextView) findViewById(R.id.passwd);
    TextView gender = (TextView) findViewById(R.id.gender);

    // 建立该Activity的Intent,作用是为了连接与上一个Activity的数据接收
    Intent intent = getIntent();

    // 利用Intent接收到的数据包,指定给新建对象
    Person p = (Person) intent.getSerializableExtra("person");

    /******id.setText方法设置显示发送过来的数据内容*********************/
    name.setText("您的用户名为:" + p.getName());
    passwd.setText("您的密码为:" + p.getPasswd());
    gender.setText("您的性别为:" + p.getGender());


    /************下面是该对象类方法的声明********************************/
    import java.io.Serializable;

    public class Person implements Serializable{
    private Integer id;
    private String name;
    private String passwd;
    private String gender;

    public Person(String name, String passwd, String gender) {
    this.name = name;
    this.passwd = passwd;
    this.gender = gender;
    }
    /***************下面省略大部分相关类方法,getName();setName();getGender();setGender();等**********************************8/




































  • 相关阅读:
    oracle 数据库服务名怎么查
    vmware vsphere 6.5
    vSphere虚拟化之ESXi的安装及部署
    ArcMap中无法添加ArcGIS Online底图的诊断方法
    ArcGIS中字段计算器(高级计算VBScript、Python)
    Bad habits : Putting NOLOCK everywhere
    Understanding the Impact of NOLOCK and WITH NOLOCK Table Hints in SQL Server
    with(nolock) or (nolock)
    What is “with (nolock)” in SQL Server?
    Changing SQL Server Collation After Installation
  • 原文地址:https://www.cnblogs.com/yhc04161120/p/4841602.html
Copyright © 2011-2022 走看看