How to dismiss the AlertDialog without buttons after clicking on any item in the Alert Dialog

by vincent Kor » Sun, 15 Mar 2009 20:22:03 GMT

Sponsored Links
 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 !!


AlertDialog.Builder<> ;
(CharSequence[]<> ;items,
int checkedItem,
DialogInterface.OnClickListener<> ;listener)

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 *


Other Threads

1. Can't make columns of RadioButtons in a RadioGroup


I have a bunch of radiobuttons in a radiogroup and I would like for
them to be arranged in two columns. The reason being so that they fit
on the screen and so that I can change the columns to be four in
landscape mode. I thought to intermingle the tablelayout with the
radiogroup. with the following code:

<TableLayout android:id="@+id/TableLayout01"
  <RadioGroup android:layout_height="wrap_content" android:id="@+id/
radiogroupChoices" android:layout_width="fill_parent">
    <TableRow android:id="@+id/TableRow01"
      <RadioButton android:layout_height="wrap_content"
android:text="One" android:id="@+id/RadioButtonOne"
android:layout_weight="1" android:layout_width="fill_parent"></
      <RadioButton android:layout_height="wrap_content"
android:text="Two" android:id="@+id/RadioButtonTwo"
android:layout_width="fill_parent" android:layout_weight="1"></
    <TableRow android:id="@+id/TableRow02"
      <RadioButton android:layout_height="wrap_content"
android:text="Three" android:id="@+id/RadioButtonThree"
android:layout_weight="1" android:layout_width="fill_parent"></
      <RadioButton android:layout_height="wrap_content"
android:text="Four" android:id="@+id/RadioButtonFour"
android:layout_weight="1" android:layout_width="fill_parent"></

In this setup, the radio buttons show up in neat columns but the
problem is the instant that I do that it takes them out of the

I tried leaving them in the TableLayout and just changing the parent
of the radiobuttons by using radiogroup.addView(eachbutton) but that
wouldn't work since they were already defined in the xml.

I also tried just having a regular radiogroup with the radiobuttons in
them and then just changing the orientation to horizontal, so that I
could set the width programatically based on the screen width

<ScrollView android:layout_width="fill_parent" android:id="@+id/
scrollviewListHolder" android:layout_height="fill_parent"
  <RadioGroup android:id="@+id/radiogroupChoices"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1" android:orientation="horizontal">
    <RadioButton android:layout_height="wrap_content"
android:text="One" android:id="@+id/RadioButtonOne"
    <RadioButton android:layout_height="wrap_content"
android:text="Two" android:id="@+id/RadioButtonTwo"

but that wouldn't work either. as many as would fit into one row would
fit and the rest would be off the screen.

Is there a way to arrange them in such a fashion while still keeping
them in the radiogroup?


2. Getting hold of PreferenceActivity Views from the xml file

I have an XML file called user_preferences that contains my
preferences for my application.

How do I get hold of the different preference Views so that I can
validate them?

Currently I have the code below which is not working because
getSharedPreferences does not return a View.

        protected void onCreate(Bundle savedInstanceState) {


                //get a handle on preferences that require validation
                timeLimitPreference = (EditTextPreference) 
("time_limit", MODE_PRIVATE);
OnPreferenceChangeListener() {

                        public boolean onPreferenceChange(Preference 
preference, Object
newValue) {
                                //Check that the string is an integer.

                                if( newValue.toString()!=null && 
{1-5}") ) {
                                        Log.e(TAG, "Not a number");
                                        newValue = 30;
                                        return true;
                                Log.e(TAG, "Is a number");
                                return false;



3. Scaling Transparent Graphics in 2.0.1

4. Google map with navigator bisa lagi euy ....

5. For Man Only

6. Where can I catch a point that is assured to be called when a Service is destroied

7. glTexImage2D gives gLError 1281 on real phone but not on emulator