android 开发之activity之间传递数据
2010-07-05 00:08:00 来源:WEB开发网}
body_height=bl.getDouble("height");
editHight.setText(""+body_height);
break;
default:
break;
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnOK = (Button) findViewById(R.id.btn_calc);
rbMan = (RadioButton) findViewById(R.id.radio_man);
rbWoman = (RadioButton) findViewById(R.id.radio_woman);
editHight = (EditText) findViewById(R.id.text_edit);
btnOK.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
try
{
body_height = Double.parseDouble(editHight.getText()
.toString());
}
catch (Exception e)
{
body_height = 0;
}
String sex = "";
if (rbMan.isChecked())
{
sex = "M";
}
else
{
sex = "F";
}
//通过intent跳转到下一个页面.
Intent intent = new Intent();
intent.setClass(ActivityBundle.this, ResultActivity.class);
//通过Bundle来获取数据,通过key-Value的方式放入数据
Bundle bl = new Bundle();
bl.putDouble("height", body_height);
bl.putString("sex", sex);
//将Bundle放入Intent传入下一个Activity
intent.putExtras(bl);
//跳到下一个Activity,并且等待其返回结果
startActivityForResult(intent, 0);
//不能够在这个Activity调用了startActivityForResult之后调用finsh()
//否则无法接收到返回
}
});
}
}
-----------------------ResultActivity.java----------------------
import java.text.DecimalFormat;
更多精彩
赞助商链接