AlertDialogpublic class AlertDialog extends Dialog implements android.content.DialogInterfaceA subclass of Dialog that can display one, two or three buttons. If you only want to
display a String in this dialog box, use the setMessage() method. If you
want to display a more complex view, look up the FrameLayout called "body"
and add your view to it:
FrameLayout fl = (FrameLayout) findViewById(R.id.body);
fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
The AlertDialog class takes care of automatically setting
{@link WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM} for you based on whether
any views in the dialog return true from {@link View#onCheckIsTextEditor()
View.onCheckIsTextEditor()}. Generally you want this set for a Dialog
without text editors, so that it will be placed on top of the current
input method UI. You can modify this behavior by forcing the flag to your
desired mode after calling {@link #onCreate}. |
Fields Summary |
---|
private com.android.internal.app.AlertController | mAlert |
Constructors Summary |
---|
protected AlertDialog(android.content.Context context)
this(context, com.android.internal.R.style.Theme_Dialog_Alert);
| protected AlertDialog(android.content.Context context, int theme)
super(context, theme);
mAlert = new AlertController(context, this, getWindow());
| protected AlertDialog(android.content.Context context, boolean cancelable, OnCancelListener cancelListener)
super(context, com.android.internal.R.style.Theme_Dialog_Alert);
setCancelable(cancelable);
setOnCancelListener(cancelListener);
mAlert = new AlertController(context, this, getWindow());
|
Methods Summary |
---|
public android.widget.Button | getButton(int whichButton)Gets one of the buttons used in the dialog.
If a button does not exist in the dialog, null will be returned.
return mAlert.getButton(whichButton);
| public android.widget.ListView | getListView()Gets the list view used in the dialog.
return mAlert.getListView();
| protected void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
mAlert.installContent();
| public boolean | onKeyDown(int keyCode, android.view.KeyEvent event)
if (mAlert.onKeyDown(keyCode, event)) return true;
return super.onKeyDown(keyCode, event);
| public boolean | onKeyUp(int keyCode, android.view.KeyEvent event)
if (mAlert.onKeyUp(keyCode, event)) return true;
return super.onKeyUp(keyCode, event);
| public void | setButton(int whichButton, java.lang.CharSequence text, android.os.Message msg)Set a message to be sent when a button is pressed.
mAlert.setButton(whichButton, text, null, msg);
| public void | setButton(int whichButton, java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when the positive button of the dialog is pressed.
mAlert.setButton(whichButton, text, listener, null);
| public void | setButton(java.lang.CharSequence text, android.os.Message msg)
setButton(BUTTON_POSITIVE, text, msg);
| public void | setButton(java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when button 1 of the dialog is pressed.
setButton(BUTTON_POSITIVE, text, listener);
| public void | setButton2(java.lang.CharSequence text, android.os.Message msg)
setButton(BUTTON_NEGATIVE, text, msg);
| public void | setButton2(java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when button 2 of the dialog is pressed.
setButton(BUTTON_NEGATIVE, text, listener);
| public void | setButton3(java.lang.CharSequence text, android.os.Message msg)
setButton(BUTTON_NEUTRAL, text, msg);
| public void | setButton3(java.lang.CharSequence text, OnClickListener listener)Set a listener to be invoked when button 3 of the dialog is pressed.
setButton(BUTTON_NEUTRAL, text, listener);
| public void | setCustomTitle(android.view.View customTitleView)
mAlert.setCustomTitle(customTitleView);
| public void | setIcon(int resId)Set resId to 0 if you don't want an icon.
mAlert.setIcon(resId);
| public void | setIcon(android.graphics.drawable.Drawable icon)
mAlert.setIcon(icon);
| public void | setInverseBackgroundForced(boolean forceInverseBackground)
mAlert.setInverseBackgroundForced(forceInverseBackground);
| public void | setMessage(java.lang.CharSequence message)
mAlert.setMessage(message);
| public void | setTitle(java.lang.CharSequence title)
super.setTitle(title);
mAlert.setTitle(title);
| public void | setView(android.view.View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom)Set the view to display in that dialog, specifying the spacing to appear around that
view.
mAlert.setView(view, viewSpacingLeft, viewSpacingTop, viewSpacingRight, viewSpacingBottom);
| public void | setView(android.view.View view)Set the view to display in that dialog.
mAlert.setView(view);
|
|