Avatar of Computer Guy
Computer Guy

asked on 

AlertDialog won't dismiss

Hi,

Using this code, my AlertDialog won't dismiss, I have to hit Ok 3-4 times before it does.

	private void correctDialog(){
		final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.setTitle("Reset...");
		alertDialog.setMessage("Are you sure?");
		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				alertDialog.dismiss();
			}
		});
		alertDialog.show();
	}

Open in new window

JavaAndroid

Avatar of undefined
Last Comment
Rafael I
Avatar of Rafael I
Rafael I
Flag of Japan image

you don't really have to tell the dialog box to dismiss itself. it just runs whatever code you want and then it dismisses itself.  for example, in one of my apps, i just set up a dialog to alert the user with a message that the list is empty and an OK button.  the rest of my code handles what happens afterwards.

		if(results.isEmpty()) {
			new AlertDialog.Builder(this)
			.setIcon(android.R.drawable.ic_dialog_alert)
			.setTitle(R.string.strEmptyTitle)
			.setMessage(R.string.strEmptyMsg)
			.setPositiveButton(R.string.strDlgOK, new DialogInterface.OnClickListener() {
			        public void onClick(DialogInterface dialog, int whichButton) {
			        	// do nothing
			        }
			}).show();
		}

Open in new window

Avatar of Computer Guy
Computer Guy

ASKER

Would the dismiss code cause it to make is so I have to hit it 4 times before it closes?
ASKER CERTIFIED SOLUTION
Avatar of Rafael I
Rafael I
Flag of Japan image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Computer Guy
Computer Guy

ASKER

I took that like out of my code and it still loops.
Avatar of Computer Guy
Computer Guy

ASKER

You can grab my project here.
http://bit.ly/1GqycJi
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

I don't do Android, but I'm wondering which setButton method you are calling there . . . some have been deprecated. Do you feel like clarifying that?
Avatar of Rafael I
Rafael I
Flag of Japan image

did you take out the command where you call dismiss()? How did it go?
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo