Java 如何计算不同的放射组?
我正在android studio中测试12个问题,想知道如何创建一个结果按钮来计算12个放射组,每个组有3个单选按钮?我在每个问题中添加了SharedReferences以保存所选按钮Java 如何计算不同的放射组?,java,android,kotlin,testing,Java,Android,Kotlin,Testing,我正在android studio中测试12个问题,想知道如何创建一个结果按钮来计算12个放射组,每个组有3个单选按钮?我在每个问题中添加了SharedReferences以保存所选按钮 RadioButton radioButton31, radioButton32, radioButton33, radioButton34, radioButton35, radioButton36; RadioGroup radioGroup11, radioGroup12; Button calcul
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);
}
});
}
}
我有5个测试意图,因此结果将基于选择的高选项。例如
问题A B C问题2 A B C
因此,我们有12个问题,有3个选项,应该给出一个int num,比如1、2或3,然后计算每个答案,如果我们有多于2或3的1,那么将是该页面的另一个意图,以显示结果1的信息
谢谢 您可以使用RadioGroup创建自定义视图,并可以在主布局中使用该视图。下面是一个带有代码的示例: