Android覆盖AlertDialog onClick

时间:2017-04-25 10:03:29

标签: java android

我在AlertDialogs的单独非活动类中使用此代码

U

我想在我的一个活动类中覆盖onClick,但我不知道如何。

2 个答案:

答案 0 :(得分:3)

您可以将点击侦听器传递给方法,并为@using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>H_Table</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.NAME, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.NAME, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.NAME, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PARENT_ID, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.PARENT_ID, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PARENT_ID, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> <div> @Html.ActionLink("Back to List", "Index") </div> </div> } 使用不同的侦听器。您将有两种方法,一种使用默认版本,另一种使用Activity可自定义:

OnClickListener

答案 1 :(得分:0)

如何将DialogInterface.OnClickListener作为参数传递给方法。

   static void alertDialogShow(Context context, String title, String message,DialogInterface.OnClickListener onClickListener) {
    final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    alertDialog.setTitle(title);
    alertDialog.setMessage(message);
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", onClickListener);
    alertDialog.show();
}