WEB开发网
开发学院手机开发Android 开发 Android Activity间用Intent和Bundle传递参数 阅读

Android Activity间用Intent和Bundle传递参数

 2010-08-29 01:48:00 来源:WEB开发网   
核心提示:传递方://点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText()private void setListeners(){btn_sub.setOnClickListener(calrBMI);}private OnClickListener calrBMI =

传递方:

//点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText()

private void setListeners()

{

btn_sub.setOnClickListener(calrBMI);

}

private OnClickListener calrBMI = new OnClickListener()

{

public void onClick(View v)

{

Intent intent = new Intent();

Bundle bundle = new Bundle();

bundle.putString("key_height", fieldHeight.getText().toString());

bundle.putString("key_weight", fieldWeight.getText().toString());

intent.setClass(ActivityMain.this,Report.class);

intent.putExtras(bundle);

startActivity(intent);

}

};

接收方:

Bundle bundle = new Bundle();

bundle = this.getIntent().getExtras();

double height = Double.parseDouble(bundle.getString("key_height"))/100;

double weight = Double.parseDouble(bundle.getString("key_weight"));

Tags:Android Activity Intent

编辑录入:coldstar [复制链接] [打 印]
赞助商链接