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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:24:41+00:00 2026-05-22T14:24:41+00:00

I have an Activity with a button, click the button to show an AlertDialog,

  • 0

I have an Activity with a button, click the button to show an AlertDialog, that works fine.
But after I click the “OK” or “Cancel” button on the AlertDialog, the AlertDialog disappears as desired, but the strange thing is that:

After the AlertDialog disappears, the Activity seems lose its focus, that means it can not receive any touches on it anymore.

Here is the code:

protected Dialog onCreateDialog(int id, Bundle args)
{
    new AlertDialog.Builder(this).create().show();
    Dialog dialog = null;
    switch(id)
    {
    case...
        break;
    case ID_DIALOG2:
        AlertDialog.Builder builder = new AlertDialog.Builder(ControlDialog.this);
        builder.setTitle("Prompt");
        builder.setMessage("Are you sure to quit?");

        builder.setPositiveButton("OK", new AlertDialog.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which) 
            {
                Log.e("AlertDialog", dialog.toString()+ " " + which);

                // do something else
                dialog.dismiss();    // even without dismiss(), the AlertDialog can disappear too.
                //ControlDialog.this.dismissDialog(ID_DIALOG2); // doesn't work either
               // dialog.cancel();    // doesn't work either
            }

        });  
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
        {
            public void onClick(DialogInterface dialog, int which) 
            {
                Log.e("AlertDialog", dialog.toString()+ " " + which);
                // do something else
                dialog.dismiss();
            }
        });

        dialog = builder.create();
        //dialog.show();
        break;
    }
    return dialog;
}

protected void onPrepareDialog(int id, Dialog dialog)
{
    switch(id)
    {
    case ...
        break;
    case ID_DIALOG2:
        ((AlertDialog)dialog).setTitle("Title");
        ((AlertDialog)dialog).setMessage("Simple Information");
        break;
    }
}

public void onClick(View v)
{
    switch(v.getId())
    {
    case R.id.show_button:
        this.showDialog(ID_DIALOG2, null);
        break;
    case ...
    }
}

Sorry, I can not post image 🙁

After clicking on “Show” button on the Activity, the AlertDialog appears.
After clicking on “OK” button on the AlertDialog, the AlertDialog disappears. BUT,
the Activity can not receive any touches.

If I click the “BACK” button of the emulator, then the Activity can receive touches again, and from then on, it will work quite good, e.g. Click “Show” button again, and then click “OK” again, after the AlertDialog disappears, the Activity is OK to receive touches without another click on the “BACK” button of emulator.

So, could anyone tell me how to tackle this problem(the Activity can not receive touches for the first time)?

TIA

  • 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-05-22T14:24:42+00:00Added an answer on May 22, 2026 at 2:24 pm

    Does your ‘Cancel’ button work properly? i.e. Does the Activity act correctly after you press it?

    I noticed this difference in your code:

    builder.setPositiveButton("OK", new AlertDialog.OnClickListener()
    
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
    

    The first line uses AlertDialog.OnClickListener and the second uses DialogInterface.OnClickListener. I just checked my code and all my dialogs use DialogInterface.OnClickListener. I’m not sure if it makes any difference but it might be worth trying DialogInterface.OnClickListener with your ‘OK’ button.

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

Sidebar

Related Questions

I have a TextViewer Activity , that has a button, and when I click
I have a ListView that uses a customized adapter, but I can't click on
I have an Activity with some buttons,if I click a specific button a new
I have a listview in my activity, and when I click on a button
I have Button.When the user click the button, there are some condition, that condition
I have an activity that extends MapActivity. I want to show map inside a
friends, i have a EditText on simple activity with a button. when every i
I have an activity that has a TabHost containing a set of TabSpecs each
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity which shows some List entries. When I click on a

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.