RadioGroup中,在不同的布局单选按钮 [英] RadioGroup with radio buttons in different layouts

查看:390
本文介绍了RadioGroup中,在不同的布局单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有单选按钮单选按钮组在自己的布局?每一个单选按钮必须是某一行上包含文本和图像。我不会用一个列表视图,因为我只有2行。

Is it possible to have a radio group with radio buttons in their own layouts? Every radio button has to be on a row that contains text and an image. I wouldn't use a list view because I only have 2 rows.

感谢了很多,

的Gratzi

推荐答案

下面是做到这一点的方式:

每个单选在XML布局文件创建一个单独的 RadioGroup中。例如:

Create a separate RadioGroup on each RadioButton in the XML layout file. For example:

<RadioGroup
    android:id="@+id/rdoFooWrapper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RadioButton
        android:id="@+id/rdoFoo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RadioGroup>

<RadioGroup
    android:id="@+id/rdoBooWrapper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RadioButton
        android:id="@+id/rdoBoo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RadioGroup>

现在,内部Java源代码code,做这样的事情:

Now, inside the java source code, do something like this:

rdoFooWrapper = (RadioGroup) findViewById(R.id.rdoFooWrapper);
rdoFoo = (RadioButton) findViewById(R.id.rdoFoo);
rdoBooWrapper = (RadioGroup) findViewById(R.id.rdoBooWrapper);
rdoBoo = (RadioButton) findViewById(R.id.rdoBoo);

rdoFoo.setOnCheckedChangeListener(this); // implement OnCheckedChangeListener to the current class
rdoBoo.setOnCheckedChangeListener(this);

// ...

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
    rdoFooWrapper.clearCheck();
    rdoBooWrapper.clearCheck();
}

这篇关于RadioGroup中,在不同的布局单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆