im making a test with 12 questions in android studio and would love to know how to create a result button that calculate 12 radiogroups with 3 radiobuttons each one? i added sharedPrefences in each question to save the selected button.
RadioButton radioButton31, radioButton32, radioButton33, radioButton34, radioButton35, radioButton36;
RadioGroup radioGroup11, radioGroup12;
Button calcularButton;
@Override
public void onBackPressed() {
startActivity (new Intent(this, MainActivity12.class));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main13);
txt31=findViewById(R.id.txt31);
txt32=findViewById(R.id.txt32);
radioButton31=findViewById(R.id.radioButton31);
radioButton32=findViewById(R.id.radioButton32);
radioButton33=findViewById(R.id.radioButton33);
radioButton34=findViewById(R.id.radioButton34);
radioButton35=findViewById(R.id.radioButton35);
radioButton36=findViewById(R.id.radioButton36);
calcularButton=findViewById(R.id.calcularButton);
radioGroup11 = findViewById(R.id.radioGroup11);
RadioButton checkedButton11 = findViewById(radioGroup11.getCheckedRadioButtonId());
radioGroup11.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
SharedPreferences settings = getSharedPreferences("RespuestasTest", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("radioButton33", radioButton33.isChecked()); // first argument is a name of a data that you will later use to retrieve it and the second argument is a value that will be stored
editor.putBoolean("radioButton32", radioButton32.isChecked());
editor.putBoolean("radioButton31", radioButton31.isChecked());
editor.commit();
}
});
radioGroup12 = findViewById(R.id.radioGroup12);
RadioButton checkedButton12 = findViewById(radioGroup12.getCheckedRadioButtonId());
radioGroup12.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
SharedPreferences settings = getSharedPreferences("RespuestasTest", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("radioButton36", radioButton36.isChecked());
editor.putBoolean("radioButton35", radioButton35.isChecked());
editor.putBoolean("radioButton34", radioButton34.isChecked());
editor.commit();
}
});
calcularButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity13.this, MainActivity14.class);
startActivity(intent);
}
});
}
}
I have 5 intents for this test, so the result will be based on the high option selected. For example.. Question A B C Question 2 A B C
so, we have 12 questions with 3 options, should give an int num like 1, 2 or 3, then count each answer, if we have more 1's than 2 or 3, then will be an other intent to that page to show the info of result 1.
Thanks!
Aucun commentaire:
Enregistrer un commentaire