早上好,我的按钮有问题。您应该做的是单击它,比较我传递的字符串,如果它与我告诉您启动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);
}
}
}
如果“ palabra”一词与“ palabrafin”一词相等,则表示意图。如果与之不同,则表示“ toast”。