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.
This is the code of the alert dialog:
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();
And here I want to end it on the clicking of the button:
Button.OnClickListener alertOnButtonClickListener = new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// code to end the alertDialog
}
};
Please tell me how to do it?
What have you do is, just create a Object of
AlertDialogusing builder.Create()method.then use
dismiss()method of AlertDialog to dismiss that dialog in button’s click.Now,