gpt4 book ai didi

android - 如何取消选中或重置单选按钮?

转载 作者:IT老高 更新时间:2023-10-28 22:19:24 25 4
gpt4 key购买 nike

我正在开发一个基于测验的应用程序。当用户打开此应用程序时,将有 1 个问题和 4 个选项(单选按钮)单选按钮将被取消选中,但当用户回答 1 个任务并且当他进行下一个任务时,将选中单选按钮。我想取消选中/重置每个问题的单选按钮。我该怎么做?

  answ1=new ArrayList<String>(new ArrayList<String>(answ1));
btn_practice1.setText(answ1.get(0));
btn_practice2.setText(answ1.get(1));
btn_practice3.setText(answ1.get(2));
btn_practice4.setText(answ1.get(3));
btn_practicerg.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton radioButton = (RadioButton)group. findViewById(checkedId); //line 262
String temp = radioButton.getText().toString();
switch(btn_practicerg.getCheckedRadioButtonId()){
case R.id.RB1:
if (btn_practice1.isChecked()){
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB2:
if (btn_practice2.isChecked()){
btn_practice1.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB3:
if (btn_practice3.isChecked()){
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB4:
if (btn_practice4.isChecked()){
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
}
break;
default:
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
ImageView nextBtn = (ImageView) findViewById(R.id.nxt_btn);
nextBtn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
btn_practicerg.clearCheck(); //line 355
}
});

Logcat

     E/AndroidRuntime(729):at    
com.example.TEENEINSTIEN.Question$LoadQuestions$2.onCheckedChanged(Question.java:262)
E/AndroidRuntime(729):at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
E/AndroidRuntime(729):at android.widget.RadioGroup.check(RadioGroup.java:166)
E/AndroidRuntime(729):at android.widget.RadioGroup.clearCheck(RadioGroup.java:205)
E/AndroidRuntime(729):at
com.example.TEENEINSTIEN.Question$LoadQuestions$3.onClick(Question.java:355)
E/AndroidRuntime(729):at android.view.View.performClick(View.java:2485)
E/AndroidRuntime(729):at android.view.View$PerformClick.run(View.java:9080)


我尝试这样,但我无法取消选中..

最佳答案

将所有按钮放在 RadioGroup 中,然后在需要清除它们时使用 RadioGroup.clearCheck();

关于android - 如何取消选中或重置单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15945285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com