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