且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从edittext获取值到字符串变量并在xamarin android中应用验证。

更新时间: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 call ToString() on a text field, it is already a string. A call to getText() will return the string containing the item's text - see EditText | Android Developers[^].