【发布时间】:2015-04-04 07:07:21
【问题描述】:
我有一个弹出的警报对话框,并通过复选框为用户提供多个选择,以及供用户输入一些文本的编辑文本。自定义警报对话框从布局膨胀,到目前为止一切都很好。
我的问题是尝试处理复选框的点击事件。我不断收到空引用异常,我无法弄清楚我哪里出错了。我尝试过以各种方式编写代码,但我认为我现在对这个问题视而不见。
我需要查看复选框是否被选中并将结果分配给我的布尔值。
在我尝试处理点击事件时抛出异常。任何帮助表示赞赏,谢谢。
var myCustomAlert = LayoutInflater.Inflate(Resource.Layout.delegateCaptureAlertLayout, null);
bool wantphoneCall = true;
bool wantBrochure = false;
bool wantMailingList = false;
string additionalText;
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(this);
builder.SetTitle("Your request");
builder.SetView(myCustomAlert);
builder.SetMessage("Some message");
builder.SetPositiveButton("OK", delegate { // do something
});
builder.Show ();
CheckBox checkCallMe = FindViewById<CheckBox> (Resource.Id.checkBoxCallMe);
CheckBox checkBrochure = FindViewById<CheckBox> (Resource.Id.checkBoxBrochure);
CheckBox checkMailingList = FindViewById<CheckBox> (Resource.Id.checkBoxMailing);
EditText additionalInfoText = FindViewById<EditText> (Resource.Id.textAdditionalInfo);
checkCallMe.Click += (sender, e) => { // exception thrown here
Console.WriteLine("Checkbox is clicked");
if (checkCallMe.Checked)
{
wantphoneCall = true;
Console.WriteLine("Checkbox is checked");
}
else
{
wantphoneCall = false;
Console.WriteLine("Checkbox is not checked");
}
【问题讨论】:
标签: android checkbox xamarin android-alertdialog nullreferenceexception