从edittext获取值到字符串变量并在xamarin android中应用验证。 [英] Getting values from edittext into string variable and apply validations in xamarin android.

查看:292
本文介绍了从edittext获取值到字符串变量并在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 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[^].


这篇关于从edittext获取值到字符串变量并在xamarin android中应用验证。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆