我正在尝试从String数组中添加动态单选按钮和文本。我能够成功地添加与“应用程序”相同数组长度的radiobuttons但是没有显示文本。任何想法?
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>
答案 0 :(得分:0)
转到此链接,我想您将了解您必须做的事情
答案 1 :(得分:0)
你的单选按钮文字是白色的,为什么它对你来说不可见。只需在你的初始化单选按钮的循环中添加以下行。
rb[m].setTextColor(Color.BLACK);