使用 edittext 作为单词检查器
Using edittext as a word checker
所以我是 java 和 android 编码编码领域的新手。
基本上我想制作一个代码检查器来检查输入的代码是否正确。如果是,那么它会给出消息 "Code Verified".
所以作为例子,我输入'Test',应该被接受。但是当我编译代码时它不起作用。
这是我当前的代码
Sub Button1_Click
If PromoCode.Text="Test" Then
Msgbox("Code Verified")
Else
Msgbox("That code is incorrect")
End If
PromoCode.text=""
End Sub
根据我的想法,这应该可行:
Button button1 = (Button) findViewById(R.id."the ID of the button");
EditText PromoCode = (EditText) findViewById(R.id."the ID of the textbox");
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(PromoCode.getText == "Test"){
Toast toast = Toast.makeText(getApplicationContext(), "Code Verified", Toast.LENGTH_SHORT);
toast.show();
}else{
Toast toast = Toast.makeText(getApplicationContext(), "That code is incorrect", Toast.LENGTH_SHORT);
toast.show();
};
PromoCode.setText = "";
}
});
所以我是 java 和 android 编码编码领域的新手。 基本上我想制作一个代码检查器来检查输入的代码是否正确。如果是,那么它会给出消息 "Code Verified".
所以作为例子,我输入'Test',应该被接受。但是当我编译代码时它不起作用。
这是我当前的代码
Sub Button1_Click
If PromoCode.Text="Test" Then
Msgbox("Code Verified")
Else
Msgbox("That code is incorrect")
End If
PromoCode.text=""
End Sub
根据我的想法,这应该可行:
Button button1 = (Button) findViewById(R.id."the ID of the button");
EditText PromoCode = (EditText) findViewById(R.id."the ID of the textbox");
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(PromoCode.getText == "Test"){
Toast toast = Toast.makeText(getApplicationContext(), "Code Verified", Toast.LENGTH_SHORT);
toast.show();
}else{
Toast toast = Toast.makeText(getApplicationContext(), "That code is incorrect", Toast.LENGTH_SHORT);
toast.show();
};
PromoCode.setText = "";
}
});