C# 4.0 Android Mono上的自定义对话框
我有这个代码,但它会在任何资源中给我一个错误。idC# 4.0 Android Mono上的自定义对话框,c#-4.0,dialog,xamarin.android,C# 4.0,Dialog,Xamarin.android,我有这个代码,但它会在任何资源中给我一个错误。id /Login Customize dialog dialog = new Dialog(this); dialog.SetContentView(Resource.Layout.login); dialog.SetTitle("Sign in to CdcSoftware App"); dialog.SetCancelable(true); //Ok
/Login Customize dialog
dialog = new Dialog(this);
dialog.SetContentView(Resource.Layout.login);
dialog.SetTitle("Sign in to CdcSoftware App");
dialog.SetCancelable(true);
//Ok
Button btnLogin = FindViewById<Button>(Resource.Id.btnLoginOK);
EditText txtUserName = FindViewById<EditText>(Resource.Id.txtUser);
TextView txtPassword = FindViewById<TextView>(Resource.Id.txtPassword);
//Cancel
Button btnCancel = FindViewById<Button>(Resource.Id.btnLoginCancel);
dialog.Show();
btnLogin.Click += delegate {Login(txtUserName, txtPassword);};
btnCancel.Click += delegate {Cancel();};
private void Login(EditText txtUserName, TextView txtPassword){
Intent intent = Intent;
string user = intent.GetStringExtra(txtUserName.ToString());
string password = intent.GetStringExtra(txtPassword.ToString());
var userObject = customers.FirstOrDefault(c => c.CustomerNumber.ToString() == user);
if (userObject != null)
{
Toast.MakeText(this, "User Id doesnt exist", ToastLength.Short).Show();
}
if(userObject.CustomerNumber.ToString().ToLower() == user && userObject.CustomerName.ToString().ToLower() == password)
{
Toast.MakeText(this, "Log in Successfully", ToastLength.Short).Show();
}
else
{
Toast.MakeText(this, "User Id or Password is Incorrect", ToastLength.Short).Show();
}
}
/Login自定义对话框
dialog=新建对话框(此对话框);
SetContentView(Resource.Layout.login);
SetTitle(“登录到CDC软件应用程序”);
对话框。可设置可取消(true);
//嗯
按钮btnLogin=FindViewById(Resource.Id.btnLoginOK);
EditText-txtUserName=FindViewById(Resource.Id.txtUser);
TextView txtPassword=findviewbyd(Resource.Id.txtPassword);
//取消
按钮btnCancel=findviewbyd(Resource.Id.btnLoginCancel);
dialog.Show();
btnLogin.Click+=委托{Login(txtsername,txtspassword);};
btnCancel.Click+=委托{Cancel();};
私有void登录(EditText-txtSerName、TextView-txtPassword){
意图=意图;
字符串user=intent.GetStringExtra(txtUserName.ToString());
字符串密码=intent.GetStringExtra(txtPassword.ToString());
var userObject=customers.FirstOrDefault(c=>c.CustomerNumber.ToString()==user);
if(userObject!=null)
{
Toast.MakeText(这个“用户Id不存在”,ToastLength.Short).Show();
}
if(userObject.CustomerNumber.ToString().ToLower()==user&&userObject.CustomerName.ToString().ToLower()==password)
{
Toast.MakeText(这是“成功登录”,ToastLength.Short).Show();
}
其他的
{
Toast.MakeText(此“用户Id或密码不正确”,ToastLength.Short).Show();
}
}
如何修复它,以及如何将此自定义对话框小部件与主类交互。我猜您需要:
Button btnLogin = dialog.FindViewById<Button>(Resource.Id.btnLoginOK);
Button btnLogin=dialog.FindViewById(Resource.Id.btnLoginOK);
而不是:
Button btnLogin = FindViewById<Button>(Resource.Id.btnLoginOK);
按钮btnLogin=FindViewById(Resource.Id.btnLoginOK);