2011-11-22 9 views
0

J'ai ce code mais son me fait une erreur dans Resource.id selon ....dialogue personnalisé sur Mono pour Android

/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(); 
     } 

    } 

Comment puis-je corriger et comment interagir ces widgets de dialogue personnalisé avec la classe principale.

Répondre

2

Je suppose que vous voulez:

Button btnLogin = dialog.FindViewById<Button>(Resource.Id.btnLoginOK); 

au lieu de:

Button btnLogin = FindViewById<Button>(Resource.Id.btnLoginOK); 
+0

Oui, je résolus hier, ce fut l'erreur, btw thx. – arkmetal