gpt4 book ai didi

Java/Android 编程/EditText -> getText().toString()

转载 作者:太空宇宙 更新时间:2023-11-03 11:31:08 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How do I compare strings in Java?
why equals() method when we have == operator?

我在这里要做的就是将在文本字段小部件中输入的文本与给定字符串(“abc”)进行比较,然后将按钮文本设置为“wrong pass”或“pass”行”。但是,即使我输入了正确的“密码”,按钮文本也总是设置为“错误的密码”。我究竟做错了什么?

public class FullscreenActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_start);

final Button button = (Button) findViewById(R.id.button);
final EditText textedit = (EditText) findViewById(R.id.textedit);

button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

if (textedit.getText().toString() == "abc")
button.setText("pass ok"); // doesn't work
else
button.setText("wrong pass");

}
});
}

...

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com