2011-11-22 95 views
0

我有這樣的代碼,但它讓我在哪個Resource.id ....自定義對話框爲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(); 
     } 

    } 

我怎麼能解決這個問題的錯誤,以及如何進行互動與此自定義對話框控件主類。

回答

2

我的猜測是你想要的:

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

代替:

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

是的,我昨天來解決,這是錯誤,順便說一句THX。 – arkmetal