AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
AddFoodActivity.this);
alertDialogBuilder.setTitle("選擇來源");
alertDialogBuilder.setCancelable(true)
.setPositiveButton("拍照",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAPTURE_IMAGE_ACTIVITY_REQ );
}
})
.setNeutralButton("相簿",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("image/*");
startActivityForResult(i, ALBUM_IMAGE_ACTIVITY_REQ );
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
建立list單選的dialog:
final CharSequence[] items = {"靜態活動(大部份時間都坐著)", "輕度活動(每天散步的人)", "中度活動(每天做劇烈運動的人)",
"重度活動(參與每日體育訓練的人)" };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("工作活動量")
.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
沒有留言:
張貼留言