WEB开发网
开发学院手机开发Android 开发 android 开发之activity之间传递数据 阅读

android 开发之activity之间传递数据

 2010-07-05 00:08:00 来源:WEB开发网   
核心提示:}body_height=bl.getDouble("height");editHight.setText(""+body_height);break;default:break;}}@Overridepublic void onCreate(Bundle savedInstan

}

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;

上一页  1 2 3 4 5 6 7  下一页

Tags:android 开发 activity

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