TextView的比较和价值观的EditText [英] Compare TextView and EditText Values

查看:123
本文介绍了TextView的比较和价值观的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想的与TextView的的比较值的EditText,但总是得到不匹配!

这是错误的方式来比较两个值?

有关的例子:我已存储的中的的TextView 的并输入相同的中的的EditText 的,但得到< STRONG>的不匹配的 ......

 的EditText editPassword;
    字符串strPassword;
    TextView的lblPassword;
    字符串密码;
    串strMatch;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.single_list_item);        editPassword =(EditText上)findViewById(R.id.editPassword);        。strPassword = editPassword.getText()的toString();        //获取数据的意图
        在意向= getIntent();        密码= in.getStringExtra(TAG_PASSWORD);        lblPassword =(的TextView)findViewById(R.id.password_label);        lblPassword.setText(密码);        。strMatch = lblPassword.getText()的toString();        btnSubmit按钮=(按钮)findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(新OnClickListener(){            @覆盖
            公共无效的onClick(查看为arg0){
                // TODO自动生成方法存根
                如果(strPassword.equals(strMatch))
                {
                  Toast.makeText(getApplicationContext()的比赛!
                                    Toast.LENGTH_LONG).show();
                  editPassword.setText(NULL);
                }
                其他
                {
                  Toast.makeText(getApplicationContext(),不匹配!
                            Toast.LENGTH_LONG).show();
                }
            }
        });
    }


解决方案

添加此行的按钮移到你的的onClick

  strPassword = editPassword.getText()的toString();

present您的EditText值是空字符串方式

I am trying to compare EditText value with TextView, but always getting "Does not match !"

Is this the wrong way to compare two values ?

For an example : I have stored win in TextView and entering same win in EditText but getting Does Not Match ......

    EditText editPassword;
    String strPassword;
    TextView lblPassword;
    String password;
    String strMatch;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);

        editPassword = (EditText) findViewById(R.id.editPassword);

        strPassword = editPassword.getText().toString();

        // getting intent data
        Intent in = getIntent();

        password = in.getStringExtra(TAG_PASSWORD);

        lblPassword = (TextView) findViewById(R.id.password_label);

        lblPassword.setText(password);

        strMatch= lblPassword.getText().toString();        

        btnSubmit = (Button) findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if(strPassword.equals(strMatch))
                {
                  Toast.makeText(getApplicationContext(), "Match !",
                                    Toast.LENGTH_LONG).show();
                  editPassword.setText(null);
                }
                else 
                {
                  Toast.makeText(getApplicationContext(), "Does not match !",
                            Toast.LENGTH_LONG).show();
                }
            }
        });        
    }

解决方案

Add this line in your onClick method of the Buttton

 strPassword = editPassword.getText().toString();

Present your edittext value is empty string means ""

这篇关于TextView的比较和价值观的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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