27.02.2014 Views

Android 开发教程

Android 开发教程

Android 开发教程

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

-----------------------------------<strong>Android</strong> 编 程 基 础<br />

}<br />

}<br />

});<br />

}<br />

/* new 一 个 Intent 对 象 , 并 指 定 class */<br />

Intent intent = new Intent();<br />

intent.setClass(Ex11_UI_A.this<br />

this, BMIActivity.class<br />

class);<br />

/* new 一 个 Bundle 对 象 , 并 将 要 传 递 的 数 据 传 入 */<br />

Bundle bundle = new Bundle();<br />

bundle.putDouble("height", height);<br />

bundle.putString("sex", sex);<br />

/* 将 Bundle 对 象 assign 给 Intent */<br />

intent.putExtras(bundle);<br />

/* 调 用 Activity EX03_10_1 */<br />

startActivityForResult(intent, my_requestCode);<br />

} catch (Exception e) {<br />

// TODO: handle exception<br />

Toast.makeText(Ex11_UI_A.this<br />

this,<br />

}<br />

R.string.errorString, Toast.LENGTH_LONG).show();<br />

@Override<br />

protected void onActivityResult(int<br />

int requestCode, int resultCode,<br />

}<br />

Intent data) {<br />

// TODO Auto-generated method stub<br />

super.onActivityResult(requestCode, resultCode, data);<br />

switch (resultCode) {<br />

case RESULT_OK:<br />

/* 取 得 来 自 Activity2 的 数 据 , 并 显 示 于 画 面 上 */<br />

Bundle bunde = data.getExtras();<br />

String sex = bunde.getString("sex");<br />

double height = bunde.getDouble("height");<br />

edit_height.setText("" + height);<br />

if (sex.equals("M")) {<br />

radiobutton_Man.setChecked(true<br />

true);<br />

} else {<br />

radiobutton_Woman.setChecked(true<br />

true);<br />

}<br />

break;<br />

default:<br />

break;<br />

}<br />

新 重 写 方 法 , 等 待 返 回 结 果<br />

24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!