Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:58:16+00:00 2026-06-04T04:58:16+00:00

My app creates an AlertDialog in which a user enters the name to save.

  • 0

My app creates an AlertDialog in which a user enters the name to save. When a user clicks the save button, the onClickListener will check for duplicated name. If the name already exists, another dialog box will pop up to alert the user that existing data will be replaced. The user then have a choice to cancel and go back to change to a new name or go ahead and have the data replace.
When the second dialog appears, I expect the first dialog box is still visible until I call dismiss. However, the first AlertDialog disappeared before the second AlertDialog appears. That is dismiss will automatically be called when a button is clicked. Is this a bug or by design?
I wrote the test case below which I checked on 3 devices: Nexus S android 4.0, HTC Rezound android 2.3 and Motorola Droid Bionic android 2.3.

Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >

    <TextView 
        android:id="@+id/message"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Some message will be here"
    />

    <Button
        android:id="@+id/show_btn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:text="Show"
    />

</LinearLayout>

Code

public class AlertDialogBug extends Activity 
{
    static final int DIALOG_ALERT_ID = 1;
    AlertDialog alertDlg;  
    TextView message;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        message = (TextView) findViewById(R.id.message);
        Button showButton = (Button) findViewById(R.id.show_btn);
        showButton.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                showDialog(DIALOG_ALERT_ID);
            }   
         });
     }

    private AlertDialog createAlertDialog()
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Bug?");

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                // No dismiss, cancel, finish, or removeDialog,
                // but the dialog will disappear when this button is clicked.
            }

          });

         alertDlg = builder.create();
         alertDlg.setOnDismissListener(new OnDismissListener()
         {

             @Override
             public void onDismiss(DialogInterface dialog)
             {
                message.setText("onDismiss was called");
             }

          });

          return alertDlg;
    }

    @Override
    protected Dialog onCreateDialog(int id)
    {
        switch (id)
        {
            case DIALOG_ALERT_ID:
                return createAlertDialog();

            default:
                return super.onCreateDialog(id);
        }       
    } 

} 

I originally wrote the save dialog box as an activity with android:theme=”@android:style/Theme.Dialog”. The UI looks fine on the Nexus S and Rezound but look terrible on the Droid Bionic (the edit box and button only occupied half of the width, the other half is blank).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:58:17+00:00Added an answer on June 4, 2026 at 4:58 am

    This is by design.
    If you don’t want to cancel the dialog by click the button, here below is some codes for you.
    Add this in your setPositiveButton method when you don’t want to cancel the dialog.

    try { 
    Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); 
    field.setAccessible(true); 
    field.set(dialog, false);
    
    } catch (Exception e) { 
    e.printStackTrace(); 
    }
    

    Then if you want to cancel the dialog, just need to add this below.

    try {
    Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
    field.setAccessible(true);
    field.set(dialog, true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    

    By the way, your xml is never called by your alert dialog. As the setTitle() and setMessage method are provided by alert dialog.

    If you want to provide custom dialog, call setCustomeView(layout).

    Any questiones, let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that creates a variable number of ScatterviewItems based on which
I have a PHP app that creates a CSV file which is forced to
I'm working on an app that creates an user profile. I need to be
i tried the following code import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import
In my app, I need to get a value from an AlertDialog which displays
I am writing a simple android app which have a edittext and a button.
My App creates a form, and saves it as a html file on SD
Since http is stateless, every request to an app creates a new object. How
I have an app that creates a SQLite database ( with 24 records ),
I have an app that creates a database and do some stuff. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.