简体   繁体   中英

In Xamarin.Android, how to make Login button disable with respect to EditText?

I'm looking how to make this funcionality on C# to Android Xamarin. It is to enable the login buttom only when the user type his user name and password. Other wise, the button shuold be disable.

My C# code doesn't work

            String edit_user_001 = (String) FindViewById<EditText>(Resource.Id.id_edit_user_001);
            String edit_password_001 = (String) FindViewById<EditText>(Resource.Id.id_edit_password_001);
            Button btn_login_001 = FindViewById<Button>(Resource.Id.id_btn_login_001);

            if (edit_user_001.Equals("") || edit_user_001.Equals("")){
                btn_login_001.Enabled = false;
            } else {
                User user = new User(edit_user_001, edit_user_001);
                btn_login_001.Enabled = true;
                btn_login_001.Click += (sender, e) => {
                    login(user);
                };
            }

Someone knows what I am doing wron?

you are trying to cast your EditText controls to string which will not work

String edit_user_001 = (String) FindViewById<EditText>(Resource.Id.id_edit_user_001);

instead

EditText edit_user_001 = FindViewById<EditText>(Resource.Id.id_edit_user_001);

then use it's Text property to access the string value

if (edit_user_001.Text.Equals("") || edit_user_001.Text.Equals(""))
        
        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM