我想做的是我头上有 3 个单选按钮说是,不,不适用
后跟 3 行中的 2 个单选按钮
我想要的是如果在 3 Rows 标题 YES 中选中所有 YES
如果在 3 行中的任何一个中检查 NO,则检查标题 No
我怎样才能做到这一点
我为此制作了 3 个无线电组
请通过图片参考
我试过的是
对于标题行
vctOptionPoint=new Vector<String>();
vctAnswerID=new Vector<String>();
int iOpCount=3;
RadioGroup rg=new RadioGroup(this);
rg.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
rg.setId(idRadioGroup);
rg.setOrientation(android.widget.RadioGroup.HORIZONTAL);
rg.setPadding(5, 0, 0, 0);
for(int j=0;j<iOpCount;j++){
String sOption="";
if(j==0){
sOption="Yes";
vctOptionPoint.addElement(sQuestionPoints);
}
else if(j==1){
sOption="No";
vctOptionPoint.addElement("0");
}
if(j==2){
sOption="NA";
vctOptionPoint.addElement("0");
}
vctAnswerID.addElement(String.valueOf(j));
RadioButton rb=new RadioButton(this);
rb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
rb.setText(sOption);
if(sAnswerText.toString().equals(sOption)){
rb.setChecked(true);
}
rb.setId(idRadioButton);
idRadioButton++;
rg.addView(rb);
}
rg.setOnCheckedChangeListener(rb_onCheckedChange);
ll.addView(rg);
第 2 行
vctOptionPoint2=new Vector<String>();
vctAnswerID2=new Vector<String>();
int iOpCount=2;
RadioGroup rg1=new RadioGroup(this);
rg1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
rg1.setId(idRadioGroup);
rg1.setOrientation(android.widget.RadioGroup.HORIZONTAL);
rg1.setPadding(5, 0, 0, 0);
for(int j=0;j<iOpCount;j++){
String sOption="";
if(j==0){
sOption="Yes";
vctOptionPoint2.addElement(sQuestionPoints);
}
else if(j==1){
sOption="No";
vctOptionPoint2.addElement("0");
}
vctAnswerID2.addElement(String.valueOf(j));
RadioButton rb1=new RadioButton(this);
rb1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
rb1.setText(sOption);
rb1.setChecked(false);
if(sAnswerText.toString().equals(sOption)){
//rb1.setChecked(true);
}
rb1.setId(idRadioButton2);
idRadioButton2++;
rg1.addView(rb1);
}
rg1.setOnCheckedChangeListener(rb_onCheckedChange_New);
相同的前 3 和 4 排
检查更改方法
OnCheckedChangeListener rb_onCheckedChange_New=new OnCheckedChangeListener(){
public void onCheckedChanged(RadioGroup rg,int arg1){
idRadioButton=4;
idRadioButton2=15;
idRadioButton1=13;
idRadioButton11=14;
int iRGChildCount=rg.getChildCount();
for(int yy=0;yy<iRGChildCount;yy++){
RadioButton rb=(RadioButton)rg.findViewById(idRadioButton);
RadioButton rb1=(RadioButton)rg.findViewById(idRadioButton2);
RadioButton rb2=(RadioButton)rg.findViewById(idRadioButton1);
RadioButton rb3=(RadioButton)rg.findViewById(idRadioButton11);
if((rb1!=null)){
if(rb1.isChecked() && rb2.isChecked() && rb3.isChecked()){
//int iQusPoints=Integer.parseInt((String)vctOptionPoint2.elementAt(idRadioButton-4));
String sOption1=rb1.getText().toString();
String sOption2=rb2.getText().toString();
String sOption3=rb3.getText().toString();
if(sOption1.equals("No") || sOption2.equals("No") || sOption3.equals("No") ){
tvSecCount1.setText("Points : 0\nScored : 0");
}
else if(sOption1.equals("Yes") || sOption2.equals("No") || sOption3.equals("No") ){
int iQusPoints=0;
tvSecCount1.setText("Points : "+sQuestionPoints+"\nScored : "+iQusPoints);
}
else if(sOption1.equals("No") || sOption2.equals("Yes") || sOption3.equals("No") ){
int iQusPoints=0;
tvSecCount1.setText("Points : "+sQuestionPoints+"\nScored : "+iQusPoints);
}
else if(sOption1.equals("No") || sOption2.equals("No") || sOption3.equals("Yes") ){
int iQusPoints=0;
tvSecCount1.setText("Points : "+sQuestionPoints+"\nScored : "+iQusPoints);
}
else if(sOption1.equals("Yes") || sOption2.equals("Yes") || sOption3.equals("No") ){
int iQusPoints=0;
tvSecCount1.setText("Points : "+sQuestionPoints+"\nScored : "+iQusPoints);
}
else if(sOption1.equals("No") || sOption2.equals("Yes") || sOption3.equals("Yes") ){
int iQusPoints=0;
tvSecCount1.setText("Points : "+sQuestionPoints+"\nScored : "+iQusPoints);
}
else{
int iQusPoints=2;
tvSecCount1.setText("Points : "+sQuestionPoints+"\nScored : "+iQusPoints);
if(sOption1.equals("Yes") && sOption2.equals("Yes") && sOption3.equals("Yes") ){
//fnNext();
}
}
}
}
idRadioButton++;
}
}
};