Android 体重测仪器开发
2010-11-05 00:55:48 来源:WEB开发网et = (EditText) findViewById(R.id.height);
double height=Double.parseDouble(et.getText().toString());
/*取得选择的性别*/
String sex="";
rb1 = (RadioButton) findViewById(R.id.sex1);
rb2 = (RadioButton) findViewById(R.id.sex2);
if(rb1.isChecked())
{
sex="M";
}
else
{
sex="F";
}
/*new一个Intent对象,并指定class*/
Intent intent = new Intent();
intent.setClass(EX03_11.this,EX03_11_1.class);
/*new一个Bundle对象,并将要传递的数据传入*/
Bundle bundle = new Bundle();
bundle.putDouble("height",height);
bundle.putString("sex",sex);
/*将Bundle对象assign给Intent*/
intent.putExtras(bundle);
/*调用Activity EX03_11_1*/
startActivityForResult(intent,0);
}
});
}
/* 覆盖 onActivityResult()*/
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
switch (resultCode)
{
case RESULT_OK:
/* 取得来自Activity2的数据,并显示于画面上 */
Bundle bunde = data.getExtras();
String sex = bunde.getString("sex");
double height = bunde.getDouble("height");
et.setText(""+height);
if(sex.equals("M"))
{
rb1.setChecked(true);
}
else
{
rb2.setChecked(true);
}
break;
default:
break;
}
}
}
Java代码
package irdc.ex03_11;
/* import相关class */
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.app.Activity;
import android.content.Intent;
更多精彩
赞助商链接