How to end the alert dialog?
<p>I am making an alert dialog in an application and want to end it when someone clicks on a particular button given in the alert dialog.Even the dismiss() and cancel() are not working for me.</p>

<p>This is the code of the alert dialog:</p>

<pre><code>    alertOnButtonDialog = new AlertDialog.Builder(this);
    TextView alertOnButtonView = new TextView(this);
    alertOnButtonView.setText("The website address of velosys consultancy services is \n velosysconsultancyservices.com.");

    Button alertOnButton = new Button(this);
    alertOnButton.setText("ok");
    alertOnButton.setOnClickListener(alertOnButtonClickListener);
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setLayoutParams( new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(1); 
    linearLayout.addView(alertOnButtonView);
    linearLayout.addView(alertOnButton);
    alertOnButtonDialog.setView(linearLayout);
    alertOnButtonDialog.show();
</code></pre>

<p>And here I want to end it on the clicking of the button:</p>

<pre><code>Button.OnClickListener alertOnButtonClickListener = new Button.OnClickListener()
    {  
        @Override  
        public void onClick(View v)
        {   
// code to end the alertDialog
        }
    };
</code></pre>

<p>Please tell me how to do it?</p>
