Thursday, June 27, 2019

java - onClickListener button problem comparing string

Good morning, I have a problem with a button. What you're supposed to do is to click on it and compare the string I'm passing and if it's the same as the one I've told you to launch the Intent.



public class SegundoActivity extends AppCompatActivity {
String palabra;
EditText letraI,letraH,letraL,letraD,letraO,letraR;
Button probar;

TextView textView8;
final String palabrafin = "IHLDOR";

private static final String TAG = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_segundo);
letraI = (EditText) findViewById(R.id.letraI);

letraH = (EditText) findViewById(R.id.letraH);
letraL = (EditText) findViewById(R.id.letraL);
letraD = (EditText) findViewById(R.id.letraD);
letraO = (EditText) findViewById(R.id.letraO);
letraR = (EditText) findViewById(R.id.letraR);
textView8 = (TextView) findViewById(R.id.textView8);
probar = (Button) findViewById(R.id.button);

String palabra1 = letraI.getText().toString().toUpperCase();
String palabra2 = letraH.getText().toString().toUpperCase();

String palabra3 = letraL.getText().toString().toUpperCase();
String palabra4 = letraD.getText().toString().toUpperCase();
String palabra5 = letraO.getText().toString().toUpperCase();
String palabra6 = letraR.getText().toString().toUpperCase();

palabra = palabra1+palabra2+palabra3+palabra4+palabra5+palabra6;

probar.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {
textView8.setText(palabra);
compare();
}

});
}

private void compare() {
if (palabra!=palabrafin) {

Toast.makeText(SegundoActivity.this,"Contrase invalida " + palabra,Toast.LENGTH_LONG).show();
}else{
Intent intent = new Intent(SegundoActivity.this, TercerActivity.class);
startActivity(intent);
}

}


}



If the word palabra its equals to the word palabrafin to launch the intent.If its not the same to launch the toast.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...