0
我需要从5个单选按钮中选取所选的单选按钮值。我曾经做过这样的:如何从android中的五个单选按钮获取选定的单选按钮值?
单选按钮值从DB:
op1=(RadioButton)findViewById(R.id.option1);
op2=(RadioButton)findViewById(R.id.option2);
op3=(RadioButton)findViewById(R.id.option3);
op4=(RadioButton)findViewById(R.id.option4);
op5=(RadioButton)findViewById(R.id.option5);
System.out.println("after lv users ");
op1.setText(listItem.getOption1());
op2.setText(listItem.getOption2());
op3.setText(listItem.getOption3());
op4.setText(listItem.getOption4());
op5.setText(listItem.getOption5());
单选检查行动:
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup rg, int checkedId) {
for(int i=0; i<radioGroup.getChildCount(); i++) {
System.out.print("radiogroup child counts");
System.out.print(radioGroup.getChildCount());
op1 = (RadioButton) radioGroup.getChildAt(i);
if(op1.isSelected()== true) {
System.out.println("radio i value");
System.out.print("option"+i);
//String text = btn.getText();
// do something with text
}
}
}
});
但它不是working.It的示值误差为NullPointerException
在line
op1.setText(listItem.getOption1());
我哪里出错了?
帮我解决这个问题。