我正在应用程序中制作一个警报对话框,并希望在有人单击警报对话框中给出的特定按钮时结束它。即使是dismiss() 和cancel() 也不适合我。
这是警报对话框的代码:
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();
在这里,我想在单击按钮时结束它:
Button.OnClickListener alertOnButtonClickListener = new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// code to end the alertDialog
}
};
请告诉我该怎么做?