从edittext获取值到字符串变量并在xamarin android中应用验证。 [英] Getting values from edittext into string variable and apply validations in xamarin android.
问题描述
嗨..,这是我使用xamarin的第一个android项目,我无法在我的代码中从EditText访问值。
什么我试过了:
EditText用户名= FindViewById< edittext>(Resource.Id.editTextUsername);
EditText密码= FindViewById< edittext>(Resource.Id.editTextPassword);
//将EditText存储在变量中
string strusername = username.ToString() ;
// string strusername = username.getText()。ToString(); (找不到getText()方法)
string strpassword = password.ToString();
if (strusername ==nworks&& strpassword ==nworks){
var showSecond = FindViewById< Button>(Resource.Id.buttonLOGIN);
showSecond.Click + =(sender,e)=>
{
StartActivity(typeof(HomeActivity));
};
您不需要在文本字段上调用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[^].
这篇关于从edittext获取值到字符串变量并在xamarin android中应用验证。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!