首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编程生成动态RadioGroup并在其上生成setOnCheckedChangeListener

编程生成动态RadioGroup并在其上生成setOnCheckedChangeListener
EN

Stack Overflow用户
提问于 2015-03-30 12:42:19
回答 2查看 1.1K关注 0票数 1

我做了下面的代码显示动态无线电组和无线电按钮。但我不明白如何将“签入”按钮转到setOnCheckedChangeListener()方法中。有一段时间,多个RadioButton将单击同一个RadioGroup。我不知道怎么回事?

代码语言:javascript
复制
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,点击每个RadioGroup都有一个必须检查的RadioButton。那么我怎样才能得到RadioButton in ButtonSubmit ClickEvent呢?

先发制人

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-30 14:13:41

Refer this..

也许它会帮助你动态地获得无线电按钮。

票数 0
EN

Stack Overflow用户

发布于 2015-03-30 12:46:18

往这边走,

代码语言:javascript
复制
RadioGroup group = new RadioGroup(this); 
group.setOrientation(RadioGroup.HORIZONTAL);
RadioButton btn1 = new RadioButton(this);
btn1.setText("BTN1");
group.addView(btn1);
RadioButton btn2 = new RadioButton(this);
group.addView(btn2);
btn2.setText("BTN2");
.... 
RadioButton btnN = new RadioButton(this);
group.addView(btnN);
btnN.setText("BTNN");
yourLayout.addView(group);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29346549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档