EDITTEXT框中不能正常工作。安卓

编程入门 行业动态 更新时间:2024-10-10 16:25:09
本文介绍了EDITTEXT框中不能正常工作。安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图获取值出来的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框中不能正常工作。安卓

本文发布于:2023-11-27 10:03:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不能正常   框中   工作   EDITTEXT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!