0

I am trying to add dynamic radio buttons and text to it from String array. I am able to add radiobuttons successfully of same array length as of "application" but text is not displayed..Any idea?

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>
Ziem
  • 6,579
  • 8
  • 53
  • 86
Christine
  • 329
  • 1
  • 4
  • 13

1 Answers1

0

Your radio button text is white that why it is not visible to you.just add below line in you for loop where you are initializing the radio button.

  rb[m].setTextColor(Color.BLACK);
Chandra Sharma
  • 1,339
  • 1
  • 12
  • 26