I am building a questionnaire type application within android and I am wondering if there is a way to randomize the final output if the if statements have the same values? In other terms I don't want one single result that occurs every time, I want the result to be randomized between 'GOOD JOB' and 'WELL DONE' does anybody know if this is possible?
Here is my Code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_system);
RadioGroup gender = (RadioGroup) findViewById(R.id.answer1);
gender.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer1A:
ans1 = 1;
break;
case R.id.answer1B:
ans1 = 2;
break;
}
}
});
RadioGroup nutrition = (RadioGroup) findViewById(R.id.answer2);
nutrition.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer2A:
ans2 = 1;
break;
case R.id.answer2B:
ans2 = 2;
break;
}
}
});
btnSubmitQuiz = (Button) findViewById(R.id.submit);
btnSubmitQuiz.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 1
if (ans1 == 1 && ans2 == 1) {
displayResult("good job");
}
if (ans1 == 1 && ans2 == 1 ) {
displayResult("well done");
}
else {
displayResult("FAIL");
}
}
private void displayResult(String result) {
Intent i = new Intent("com.example.system.SHOWRESULT");
i.putExtra("unique_constant", result);
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.system, menu);
return true;
}
}