java - 如何计算不同的无线电组?
问题描述
我在 android studio 中进行了 12 个问题的测试,并且很想知道如何创建一个结果按钮来计算 12 个单选组,每个单选按钮有 3 个单选按钮?我在每个问题中添加了 sharedPrefences 以保存选定的按钮。
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 个意图,因此结果将基于所选的高选项。例如.. 问题 ABC 问题 2 ABC
所以,我们有 12 个问题和 3 个选项,应该给出一个像 1、2 或 3 这样的 int num,然后计算每个答案,如果我们的 1 比 2 或 3 多,那么该页面将是另一个显示信息的意图结果1。
谢谢!
解决方案
推荐阅读
- python-3.x - 使用 browser.page_source 读取时 page_source 内容不会改变
- php - PHP 和 Dart 双向加密
- javascript - 为什么我的正则表达式没有通过这种情况(包括代码)
- javascript - 我已经用 JavaScript 编写了用于点分页的代码。我希望这段代码得到优化和改进。我怎样才能实现它?
- android - Firestore中没有来自滑翔的图像
- java - 输入正确,但输出与输入不匹配
- python - Executemany 在 INSERT 上将“参数数量无效(预期为 12,得到 71625)”抛出到 SQL Server 表中
- ruby - 如何从 ruby 脚本打开 xterm 并在此 xterm 中显示?
- flutter-web - 运行flutter web时如何指定端口号
- c++ - 计算偶数平均值时出现浮点异常错误