更新时间:2023-11-14 09:43:28
您不需要在文本字段上调用ToString()
,它已经是一个字符串。对getText()
的调用将返回包含项目文本的字符串 - 请参阅 EditText | Android开发者 [ ^ ]
Hi.., this is my first project of android using xamarin and I am not able to access value from EditText in my code.
What I have tried:
EditText username = FindViewById<edittext>(Resource.Id.editTextUsername);
EditText password = FindViewById<edittext>(Resource.Id.editTextPassword);
// Store EditText in Variable
string strusername = username.ToString();
// string strusername = username.getText().ToString(); (getText() method not found)
string strpassword = password.ToString();
if (strusername == "nworks" && strpassword == "nworks") {
var showSecond = FindViewById<Button>(Resource.Id.buttonLOGIN);
showSecond.Click += (sender, e) =>
{
StartActivity(typeof(HomeActivity));
};
You do not need to callToString()
on a text field, it is already a string. A call togetText()
will return the string containing the item's text - see EditText | Android Developers[^].