1.獲得 RadioButton值
[java]
rb1 = (RadioButton)findViewById(R.id.sex1);
if (rb1.isChecked())
{
sex = "M";
} else
{
sex = "F";
}
2.兩個Activity間傳遞資料
[java]
發送方:
Intent intent = new Intent();
intent.setClass(EX03_11.this,EX03_11_1.class);
Bundle bundle = new Bundle();
bundle.putDouble("height", height);
bundle.putString("sex", sex);
intent.putExtras(bundle);
//開啟另一個activity
startActivityForResult(intent, 0);
接受方:
intent =this.getIntent();
bundle=intent.getExtras();
String sex =bundle.getString("sex");
double height =bundle.getDouble("height");
3.開啟一個訊息框
[java]
new AlertDialog.Builder(EX03_12.this)
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setPositiveButton(R.string.str_ok,
newDialogInterface.OnClickListener()
{
publicvoid onClick(DialogInterface dialoginterface, int i)
{
} www.2cto.com
}).show();
4.改變文字框的字型
mText.setTypeface(Typeface.createFromAsset(getAssets(),
"fonts/HandmadeTypewriter.ttf"));
注: 在assets目錄下建立fonts檔案夾並放入HandmadeTypewriter.ttf字型檔