1.MainActivity.java
public class MainActivity extends Activity {
private EditText mUsrnameEdt;
private EditText mPasswdEdt;
private Button mRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mUsrnameEdt = (EditText) findViewById(R.id.username_edit);
mPasswdEdt = (EditText) findViewById(R.id.passwd_edit);
mRegister = (Button) findViewById(R.id.zhuce);
mRegister.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Person p = new Person(mUsrnameEdt.getText().toString(),
mPasswdEdt.getText().toString());
Bundle data = new Bundle();
data.putSerializable("person", p);
Intent intent = new Intent(MainActivity.this,ShowResult.class);
intent.putExtras(data);
startActivity(intent);
}
});
}
}
2.ShowResult.java
public class ShowResult extends Activity {
private TextView mShowName;
private TextView mShowPsswd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
mShowName = (TextView)findViewById(R.id.user);
mShowPsswd = (TextView)findViewById(R.id.psswd);
Intent intent = getIntent();
Bundle data = intent.getExtras();
Person p = (Person)data.getSerializable("person");
mShowName.setText(p.getName());
mShowPsswd.setText(p.getPass());
}
}
3.Person.java
package com.example.bundledemo;
import java.io.Serializable;
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
private String pass;
public Person() {
}
/**
* @param name
* @param pass
* @param gender
*/
public Person(String name, String pass) {
this.name = name;
this.pass = pass;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}