[android-developers] Re: How to dismiss the AlertDialog without buttons after clicking on any item in the Alert Dialog

2009-03-16 Thread vincent Kor
help me !!  Really appreciate your help !!!

Vincent


 Hi, All:
>
> from the reference of SDK,  AlertDialog information as below.
>
>I want to create an alert dialog without any buttons, but there are
> 3 items(radio), then i hope to dismiss the dialog after i click any item in
> the dialog,  how should i dismiss the dialog ?
>
>
> Really appreciate your help !!
>
> Vincent
>
>
> --
>  public 
> AlertDialog.Builder
> setSingleChoiceItems 
> (CharSequence[]items,
>  int checkedItem,
> DialogInterface.OnClickListenerlistener)
>
> Set a list of items to be displayed in the dialog as the content, you will
> be notified of the selected item via the supplied listener. The list will
> have a check mark displayed to the right of the text for the checked item.
> Clicking on an item in the list will not dismiss the dialog. Clicking on a
> button will dismiss the dialog.
>  Parametersitems the items to be displayed. checkedItem specifies
> which item is checked. If -1 no items are checked. listener
>
> notified when an item on the list is clicked. The dialog will not be
> dismissed when an item is clicked. It will only be dismissed if clicked on a
> button, *if no buttons are supplied it's up to the user to dismiss *
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: How to dismiss the AlertDialog without buttons after clicking on any item in the Alert Dialog

2009-03-15 Thread Greg Krimer

If you don't want buttons then you probably don't want to use
AlertDialog because an AlertDialog has to have at least one button.
Instead, use the Dialog class that AlertDialog extends. A Dialog can
display any view hierarchy you want. You can then attach listeners to
one or more views in your hierarchy that will cancel the dialog. Here
is a really simple example:

// assuming the dialog is constructed within your activity
final Dialog d = new Dialog(this);
d.setTitle("My Dialog");
TextView t = new TextView(this);
t.setText("Click me to dismiss the dialog");
t.setClickable(true);
t.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
d.dismiss();
}
});
d.setContentView(t);
d.show();

Of course, you would want to define your view hierarchy in XML and use
setContentView(int) instead.

Take a look at the documentation for the Dialog class to see what
methods are available. In particular there is a method
setCanceledOnTouchOutside() which I guess is the opposite of what you
want, but is interesting nonetheless.

Hope this helps,

Greg

On Mar 15, 5:21 am, vincent Kor  wrote:
> Hi, All:
>
>     from the reference of SDK,  AlertDialog information as below.
>
>     I want to create a dialog but i don't want to have any buttons in the
> dialog, then i hope to dismiss the dialog after i click any item in the
> dialog,  how should i dismiss the dialog ?
>
>     When the user click the "back" button, it will dismiss the dialog.  so i
> need to send the key message in hard code ? is there any other way??
>
>     Really appreciate your help !!
>
> Vincent
>
> --
>  public 
> AlertDialog.Builder
> setSingleChoiceItems
> (CharSequence[]items,
> int checkedItem,
> DialogInterface.OnClickListenerlistener)
>
> Set a list of items to be displayed in the dialog as the content, you will
> be notified of the selected item via the supplied listener. The list will
> have a check mark displayed to the right of the text for the checked item.
> Clicking on an item in the list will not dismiss the dialog. Clicking on a
> button will dismiss the dialog.
>  Parameters    items the items to be displayed. checkedItem specifies which
> item is checked. If -1 no items are checked. listener
>
> notified when an item on the list is clicked. The dialog will not be
> dismissed when an item is clicked. It will only be dismissed if clicked on a
> button, *if no buttons are supplied it's up to the user to dismiss *
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---