1

So I'm new to the world of java & android coding coding. Basically I want to make a code checker that checks if the code entered is correct. If it is then it gives the message "Code Verified".

So as an example, I enter 'Test', which should be accepted. But when I compile the code it doesn't work.

Here is my current code

  Sub Button1_Click
If PromoCode.Text="Test" Then
  Msgbox("Code Verified")
Else
  Msgbox("That code is incorrect")
End If
    PromoCode.text=""
End Sub
Flan
  • 39
  • 8
MrMC
  • 113
  • 4
  • 1
    Linking to pictures of code is generally frowned upon - there's no telling when the image host will die, leaving a mystery question. Can you post your code in full in your question please? – goobering May 11 '15 at 15:54
  • possible duplicate of [Get Value of a Edit Text field](http://stackoverflow.com/questions/4531396/get-value-of-a-edit-text-field) – Froyo May 11 '15 at 16:52

1 Answers1

1

From the top of my head, this should work:

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

   }
 });
Fábio Santos
  • 199
  • 1
  • 2
  • 16