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 8102095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:09:15+00:00 2026-06-05T23:09:15+00:00

In my application, I have created a dialog box to accept password. In the

  • 0

In my application, I have created a dialog box to accept password. In the dialog a message, an EditText and two buttons (one +ve and one -ve) are present. When user clicks on the +ve button, I am checking whether the password entered in the EditText is valid or not. If not valid, I have to change the message of the dialog box prompting the user to re-enter the password again.

If the password is valid it works as per the expectation, but it is invalid, instead of updaing the message it simply closes the dialog.

I have already tried to solve it by overriding onPrepareDialog(), but it also doesn’t work.

Here is my code:

protected Dialog onCreateDialog(int viewId){
    AlertDialog dialog = null;
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Enter Password To Continue");
            final EditText passwordField = new EditText(getApplicationContext());
            builder.setView(passwordField);
            builder.setPositiveButton("SUBMIT", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    if(passwordField.getText().toString().equals("password")){
                        Intent intent = new Intent(MyFirstActivity.this, NextActivity.class);
                        finish();
                        startActivity(intent);
                    }else{
                            //Here I need to update the message
                        builder.setMessage("SORRY!!! Wrong Password Entered.\n Re-Enter Correct Password Again ");
                    }                       
                }
            });
            builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            dialog =  builder.create();
    }
    return dialog;
}
  • 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-05T23:09:16+00:00Added an answer on June 5, 2026 at 11:09 pm

    I think there are 2 issues here.

    1. If I recall correctly the default behavior of the PositiveButton on an AlertDialog will close the dialog. I think that is why yours is closing when the password is wrong. I think if you switch to

      builder.setNeutralButton(...);
      

      it will not close your dialog when pressed.

    2. You are changing the message on the Builder instead of the Dialog itself. I don’t think the Builder will dynamically change the way the Dialog looks once it has already been created and shown.

      dialog.setMessage("WRONG PASSWORD");
      

    will change it for you I think. If not then you’ll have to make a TextView and add it to your Dialog with builder.setView(mTxt); then you can call setText(); on your reference and it will change the text on the screen.

    I think a better solution than either might be a Toast pop-up though. The user has just typed a password and pressed submit so I think they can be counted on to be looking at the screen. Many other applications that have logins pages use Toast message to tell the user if they got the password wrong, so I don’t think you’ll be confusing your users or anything, it is a common design patter.

    EDIT:

    AlertDialog class definitely does have a setMessage() method. see the docs here. It is near the bottom of the docs page so it won’t scroll it to the top when you click the link correctly. But it is there, 3rd one down from the top for me. Between setInverseBackgroundForced and setTitle

    EDIT 2:

    I implemented something similar to what you are trying to do a while ago. I had to use my own Custom Listener object with the dialog buttons I think in order to get them to not hide the Dialog upon being pressed.

    Here is how I create and show the dialog:

      AlertDialog.Builder builder = new AlertDialog.Builder(YourActivity.this);
      builder.setCancelable(false)
      .setMessage("Please Enter Something")
    
      .setPositiveButton("Enter", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
            //All of the fun happens inside the CustomListener now.
            //I had to move it to enable data validation.
            }
       });
       AlertDialog alertDialog = builder.create();
       alertDialog.show();
       Button theButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
       theButton.setOnClickListener(new CustomListener(alertDialog));
    

    Then I created an Inner class inside my Activity called CustomListener like this:

    class CustomListener implements View.OnClickListener {
        private final Dialog dialog;
        public CustomListener(Dialog dialog) {
            this.dialog = dialog;
        }
        @Override
        public void onClick(View v) {
    
    
            if(passwordField.getText().toString().equals("password")){
                //Password is correct.
    
    
            } else { //Password is incorrect.
                ((AlertDialog)dialog).setMessage("WRONG");
            }
        }
    }
    

    When you set the listener in this manner it will not close the Dialog automatically upon button press.

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

Sidebar

Related Questions

I am using windows forms application using C#. I have created a dialog box
I have created a Vb application/exe using ADODC components and common dialog box. but
I have created a dialog box in my WinForms application. This has many text
I have created a Dialog Box in a c++ windows application (using ATL lib)
I have created a play application and have some models. One of them contains
I have created one Catalyst application and I have created Schema and Model using
I have created Custom Dialog for my application. While i run that application in
I have created a custom dialog box which requires 3 fields public class Test{
I am developing an android application. Now i have created one function which create
A long time ago I created a dialog box in my application. The dialog

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.