我在下面制作了用于显示动态单选组和单选按钮的代码。但我不明白如何将检查按钮放入setOnCheckedChangeListener()
方法中。有时多个 RadioButton 会点击同一个 RadioGroup。我不知道怎么办?
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll);
menuSize = 4;
for(i = 0; i < menuSize; i++)
{
int menuId = controller.getMenuid(i));
int subMenuSize = controller.getSubMenu(menuId).size(); // Dynamic value from MVC architechture
TextView textViewHeading = new TextView(getApplicationContext()); // RadioGroup Heading
textViewHeading.setText(controller.getMenuName(i)); // Set RadioGroup Heading
linearLayout.addView(textViewHeading);
RadioGroup radioGroup = new RadioGroup(getApplicationContext());
radioGroup.setId(i);
for(j = 0; j < subMenuSize; j++)
{
RadioButton radioButton = new RadioButton(getApplicationContext());
radioButton.setId(j);
// Get value from HashMap<Integer, ArrayList<SubMenuClass>>
// Value is used for RadioButton
radioButton.setText( controller.getSubMenu(menuId).get(j).getSubMenuName());
radioGroup.addView(radioButton);
}
radioGroup.setOnCheckedChangeListener(TryRadioButtons.this);
linearLayout.addView(radioGroup);
}
我想检查 ButtonSubmit Click 是否每个 RadioGroup 都必须检查一个 RadioButton。那么如何在 ButtonSubmit ClickEvent 中获取 RadioButton?
提前致谢