두 라디오 버튼을 프로그래밍 방식으로 라디오 그룹에 만듭니다. 두 버튼을 모두 클릭하면 선택됩니다. 라디오 버튼 속성을 따르지 않는 것을 의미합니다. 예와 아니오 두 가지 옵션이 있습니다. 한 번에 하나씩 확인하는 것은 둘 다 아닙니다. 내 코드는 ... 아래에 있기 때문에 당신이에 동일한 ID를 사용하는 프로그래밍 라디오 버튼을 추가하여 사전RadioGroup이 제대로 작동하지 않습니다.
public static void YesNoQuestion(Context context , View v,Question_Bean ques ,int ParentView){
LinearLayout linearLayout = (LinearLayout) v.findViewById(ParentView);
LayoutParams lp = new LayoutParams (LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
TextView question = new TextView(context);
question.setText(ques.getQuestion());
question.setTag(ques.getQid());
RadioGroup rgroup = new RadioGroup(context);
rgroup.setOrientation(RadioGroup.VERTICAL);
RadioButton optionYes = new RadioButton(context);
optionYes.setText(" Yes ");
RadioButton optionNo = new RadioButton(context);
optionNo.setText(" No ");
rgroup.addView(optionYes,lp);
rgroup.addView(optionNo,lp);
linearLayout.addView(question,lp);
linearLayout.addView(rgroup,lp);
}
확인 여기 : http://stackoverflow.com/questions/19929295/crreating-radiogroup-programmatically – msysmilu
방법이 링크 도움이 문제를 해결해야합니까? – Opiatefuchs
@msysmilu 주어진 링크의 해결책은 무엇입니까? 나는 비슷한 과정을 만들었습니다 ... –