[英]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.我正在寻找如何在 C# 到 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我的 C# 代码不起作用
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您正在尝试将EditText
控件转换为不起作用的string
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然后使用它的Text
属性来访问字符串值
if (edit_user_001.Text.Equals("") || edit_user_001.Text.Equals(""))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.