Verification for true @ false
-
The code is as follows:
Quest[] statements = new Quest[3];
private void fillQuestions() {
statements[0] = new Quest("Столица России - это Казань", false);
statements[1] = new Quest("Камень крепкий", true);
statements[2] = new Quest("Музыка - это прекрасно", true);
}private void textShow() {
TextView qustions = (TextView) findViewById(R.id.statements);
qustions.setText(statements[0].statement);
Button btnTrue = (Button) findViewById(R.id.bt_true);
Button btnFalse = (Button) findViewById(R.id.lie);
btnTrue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Угадал!", Toast.LENGTH_SHORT).show();
}
});
btnFalse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Не угадал!", Toast.LENGTH_LONG).show();
}
});
}
How do you make the right check on the answer?
-
I understand the button.
btnTrue
corresponds to the fact that the allegation is correct, andbtnFalse
- that's wrong. The correct value is stored in the second parameter of the objectQuest
- because your question doesn't make it clear what it's called the second field, I've named it conditionally.valid
Like:Quest[] statements = new Quest[3];
private void fillQuestions() {
statements[0] = new Quest("Столица России - это Казань", false);
statements[1] = new Quest("Камень крепкий", true);
statements[2] = new Quest("Музыка - это прекрасно", true);
}private void textShow() {
TextView qustions = (TextView) findViewById(R.id.statements);
qustions.setText(statements[0].statement);
Button btnTrue = (Button) findViewById(R.id.bt_true);
Button btnFalse = (Button) findViewById(R.id.lie);
btnTrue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isTrue(statements[0].valid);
}
});
btnFalse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isTrue(!statements[0].valid);
}
});void isTrue( boolean isTrue){
String valid = (isTrue) ? "Угадал!" : "Не угадал!";
Toast.makeText(MainActivity.this, valid, Toast.LENGTH_LONG).show();
}
}
It's worth noting that your quiz game is a little wrong. With very good and more detailed examples of the quiz game, you can read the books:
Brian Hardy, Bill Phillips - Android programming, 2014 - an example from this book - the first "GeoQuiz"
P. Datell is "Android for programmers. Create annexes, 2012, Chapter 6: Annex Flag Quiz Game