0
我想从字符串数组中添加动态单选按钮和文本。我能够成功添加与“应用程序”相同的数组长度的单选按钮,但文本不显示。任何想法?无法将文本添加到动态单选按钮
private String[] application = {"ABC", "DEF", "GHI", "JKL"};
RadioButton[] rb = null;
radioGroup = (RadioGroup) mLinearView3.findViewById(R.id.myRadioGroup);
rb = new RadioButton[application.length];
for(int m = 0; m < application.length; m++) {
rb[m] = new RadioButton(getApplicationContext());
rb[m].setText(application[m]);
rb[m].setId(m);
radioGroup.addView(rb[m]);
}
mLinearScrollThird.addView(mLinearView3);
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:id="@+id/myRadioGroup"
android:background="#fff"
android:checkedButton="@+id/sound">
</RadioGroup>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
</LinearLayout>
显示布局,其中radioGroup中躺在 –
感谢@NikMyers,增加了布局 – Christine
也许你正在使用某种形式的黑暗风格,和文字应为白色,所以白色backgeound你看不到吗?我不确定,但只需检查它,更改背景颜色或为单选按钮设置颜色 –