The Android API supports the following types of Dialog
objects:
AlertDialog 알림
- A dialog that can manage zero, one, two, or three buttons, and/or a list of selectable items that can include checkboxes or radio buttons. The AlertDialog is capable of constructing most dialog user interfaces and is the suggested dialog type. See Creating an AlertDialog below.
ProgressDialog
- A dialog that displays a progress wheel or progress bar. Because it's an extension of the AlertDialog, it also supports buttons. See Creating a ProgressDialog below.
DatePickerDialog 날짜 선택
- A dialog that allows the user to select a date. See the Hello DatePicker tutorial.
TimePickerDialog 시간 선택
- A dialog that allows the user to select a time. See the Hello TimePicker tutorial.
If you would like to customize your own dialog, you can extend the base Dialog
object or any of the subclasses listed above and define a new layout. See the section on Creating a Custom Dialog below.
다양한 대화창/ 알림창/
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to exit?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { MyActivity.this.finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create();
Adding a List
final CharSequence[] items = {"Red", "Green", "Blue"}; AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("Pick a color"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); }}); AlertDialog alert = builder.create();
Adding checkboxes and radio buttons
final CharSequence[] items = {"Red", "Green", "Blue"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Pick a color"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); }}); AlertDialog alert = builder.create();
Creating a ProgressDialog
ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", "Loading. Please wait...", true);
Showing a progress bar
ProgressDialog progressDialog;progressDialog = new ProgressDialog(mContext); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage("Loading..."); progressDialog.setCancelable(false);
Creating a Custom Dialog
Context mContext = getApplicationContext(); Dialog dialog = new Dialog(mContext); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Custom Dialog"); TextView text = (TextView) dialog.findViewById(R.id.text); text.setText("Hello, this is a custom dialog!"); ImageView image = (ImageView) dialog.findViewById(R.id.image); image.setImageResource(R.drawable.android);
'0.일반개발' 카테고리의 다른 글
EditText (0) | 2010.09.15 |
---|---|
EditText (0) | 2010.09.15 |
showKeypad (0) | 2010.09.15 |
이동, 회전, 크기 등의 속성을 변경 (0) | 2010.09.15 |
Android Framwork 마인드 맵 (0) | 2010.09.15 |