1

我正在开发安卓应用程序。因为我需要根据特定大小动态显示单选按钮。我能够显示带有 1、2、3 的单选按钮。

喜欢

1. text1
2. text2
3. text3

但是我怎样才能显示如下的单选按钮

a. text1
b. text2
c. text3

任何帮助将不胜感激

4

1 回答 1

0

您必须在布局文件中创建一个 RadioGroup

<TableRow>
    <RadioGroup
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/radiobuttons">
    </RadioGroup>
</TableRow>

然后以编程方式向其添加按钮并根据需要设置文本而不是数字:

public void makeRadioButtons(Vector tmpVector, int i,
LinearLayout.LayoutParams lp)
{
    RadioButton rb = new RadioButton(this);
    rb.setText((String) tmpVector.elementAt(i));
    //rg is private member of class which refers to the radio group which you can find   by id.
    rg.addView(rb, 0, lp);

}

希望这可以帮助。

于 2013-06-25T05:35:07.687 回答