![微笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
public class MainActivity extends Activity {
// 声明按钮Button
private Button register,cancel;
// 声明ToggleButton
private ToggleButton marriged;
// 声明单选按钮
private RadioButton male,female;
// 声明文本编辑框
private EditText username,password;
// 声明下拉列表
private Spinner position;
// 声明多选按钮
private CheckBox reading,swimming;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 获取EditText
username =(EditText)findViewById(R.id.username);
password =(EditText)findViewById(R.id.password);
// 获取RadioButton
male = (RadioButton)findViewById(R.id.male);
female = (RadioButton)findViewById(R.id.female);
// 获取CheckBox
reading = (CheckBox)findViewById(R.id.reading);
swimming = (CheckBox)findViewById(R.id.swimming);
// 获取ToggleButton
marriged = (ToggleButton)findViewById(R.id.marriged);
// 获取Spinner
position = (Spinner)findViewById(R.id.position);
// 下拉列表数组
String[] str = {"CEO","程序员","软件设计师","系统分析师"};
// 数组下拉列表适配器
ArrayAdapter aadapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,str);
// 设置下拉列表适配器
position.setAdapter(aadapter);
// 获取按钮
register = (Button)findViewById(R.id.register);
cancel = (Button)findViewById(R.id.cancel);
// 为按钮添加单击事件
register.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Bundle b = new Bundle();
b.putString("username", "用户名称:"+username.getText().toString());
b.putString("password", "用户密码:"+password.getText().toString());
if(male.isChecked())
{
b.putString("gender", "性别:男");
}else{
b.putString("gender", "性别:女");
}
String aihao = "爱好:";
if(reading.isChecked())
{
aihao+="阅读";
}
if(swimming.isChecked())
{
aihao+=" ";
aihao+="游泳";
}
b.putString("hobby", aihao);
if(marriged.isChecked())
{
b.putString("marriged", "婚否:已婚");
}
else{
b.putString("marriged", "婚否:未婚");
}
b.putString("position","职位:"+position.getSelectedItem().toString());
Intent intent = new Intent(MainActivity.this,ResultActivity.class);
intent.putExtra("data", b);
startActivity(intent);
}
});
}
}
下面是第二个activity
public class ResultActivity extends Activity
{
ListView listView ;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
listView = (ListView)findViewById(R.id.ListView01);
Intent intent = getIntent();
Bundle b = intent.getBundleExtra("data");
ArrayList<String> list = new ArrayList<String>();
list.add(b.getString("username"));
list.add(b.getString("password"));
list.add(b.getString("position"));
list.add(b.getString("gender"));
list.add(b.getString("hobby"));
list.add(b.getString("marriged"));
ArrayAdapter aadapter = new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,list);
listView.setAdapter(aadapter);
}
}
本程序效果图: