editText box not working properly. Android

前端 未结 2 1729
无人共我
无人共我 2021-01-29 14:42

I\'m trying to get values out of edittext boxes and on the click of a button, I want to compare if the text inside the edittext box matches a certain value. If it does, a new in

相关标签:
2条回答
  • 2021-01-29 14:50

    Use

    if(id.equals("abc"))
    

    instead Of

     if(id == "abc")
    
    0 讨论(0)
  • 2021-01-29 14:54

    Try this.. if id is int use like this id == 5. but id is String you should use id.equals("abc")

    if(id.equals("abc")){           //Correction is here
                Intent i= new Intent(Slogin.this, Sales.class);
                startActivity(i);
            }else{
                Toast toast = Toast.makeText(this, "Wrong id pass",                                                                            Toast.LENGTH_SHORT);
                toast.show();
            }
    

    == always just compares two references (for non-primitives, that is) - i.e. it tests whether the two operands refer to the same object.

    However, the equals method can be overridden - so two distinct objects can still be equal......

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