使用EditText作为单词检查器



,所以我是Java&Android编码编码。基本上,我想制作一个代码检查器,以检查输入的代码是否正确。如果是,则会给出消息"代码验证"。

因此,我输入"测试",应接受。但是当我编译代码时,它不起作用。

这是我当前的代码

  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 = "";
   }
 });

最新更新