How do I close an Android alertdialog
<p>I am developing a quiz and I need the user to answer all the questions before proceeding.  When the user has not answered all the questions I display a simple alertdialog informing him or her. The problem is whatever I do I can't get the alertdialog to close.  Why isn't dialog.cancel working?`This is the code: </p>

<pre><code>AlertDialog.Builder ad = new AlertDialog.Builder(this);  
ad.setTitle("Unanswered Questions");  
ad.setMessage("You have not answered all the questions.");   
ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {  
   public void onClick(DialogInterface dialog, int id) {  
     dialog.cancel(); 
}  
});  
ad.show(); 
</code></pre>
