我试图获取值出来的EditText框和一个按钮的点击,我想如果的EditText框内的文字一定值匹配比较。如果是这样,一个新的意图应被调用。如果没有它应该显示一个错误。下面是我在点击按钮后,code ...
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 intent should be called. If it doesn't it should show an error. Here is my code after the button is clicked...
if(v.getId() == R.id.button1){ id = et1.getText().toString(); Toast toast = Toast.makeText(this, "Value of id is: " + id, Toast.LENGTH_SHORT); toast.show(); if(id == "abc"){ Intent i= new Intent(Slogin.this, Sales.class); startActivity(i); }else{ Toast toast = Toast.makeText(this, "Wrong id pass", Toast.LENGTH_SHORT); toast.show(); }现在的问题是,即使当我输入ABC(不包括双引号),它仍然显示我的错误错号通。虽然吐司清楚地表明,我已进入ABD和字符串ID现在持有的价值ABC。帮助需要...
Now the problem is that even when I enter "abc" (without the double commas), it still shows me the error "Wrong id pass". While the Toast clearly shows that I have entered abd and the string id now holds the value "abc". Help required...
推荐答案试试这个。如果 ID 是 INT 使用这样 ID == 5 。但id是字符串你应该使用 id.equals(ABC)
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......
更多推荐
EDITTEXT框中不能正常工作。安卓
发布评论