Comparing two editTexts in android

前端 未结 6 1531
既然无缘
既然无缘 2020-12-22 05:01

I am learning android I tried following codeline but it\'s giving me error please give me suggestions, that how can I compare two edittext\'s text.



        
相关标签:
6条回答
  • 2020-12-22 05:26
    if( (edt1.getText().toString()=="X")&&(edt4.getText().toString()=="X")&&(edt7.getText().toString()=="X") )
    
    0 讨论(0)
  • 2020-12-22 05:27

    if you want to check edt1, edt4, edt7 have "X" value then try this..

    if((edt1.getText().toString().equalsIgnoreCase("X")     
                   &&edt4.getText().toString().equalsIgnoreCase("X") && 
                  edt7.getText().toString.equalsIgnoreCase("X"))
    
    0 讨论(0)
  • 2020-12-22 05:27

    Make it simple:

    if (!et1.toString().equals(et2.toString())) {
        MsgBox(this,"--Your Message--");
    }
    
    0 讨论(0)
  • 2020-12-22 05:35

    Please try this:

    if((edt1.getText().toString.equalsIgnoreCase("X")) && 
       (edt4.getText().toString.equalsIgnoreCase("X")) && 
       (edt7.getText().toString.equalsIgnoreCase("X")))
    

    If you have to compare strings then you need to call the equals or equalsIgnoreCase function of String.

    0 讨论(0)
  • 2020-12-22 05:38

    Here's a solution that doesn't violate the DRY principle:

    private static boolean allContain(final String value, 
                                      final EditText... editTexts)
    {
    
        for (EditText editText : editTexts) {
            final String text = editText.getText().toString();
            if (!text.equals(value)) {
                return false;
            }
        }
        return true;
    }
    

    You can use it as follows:

    if (allContain("X", edt1, edt2, edt3, edt4)) {
        // All EditTexts contain 'X'
    }
    
    0 讨论(0)
  • 2020-12-22 05:50

    I have find the best solution..

    if(Password.getText().toString().trim().matches(confirmPassword.getText().toString().trim()))
    {
    // then do your work
    }
    else
    //otherwise show error message.
    

    whereas

    Password = (EditText)findViewById(R.id.pass);
    
    confirmPassword = (EditText)findViewById(R.id.confirmpass);
    

    are two editText.

    0 讨论(0)
提交回复
热议问题