title: Android Custom Checkbox/RadioButton Text Not Displaying
body: <p>I'm trying to create custom RadioButtons/Checkboxes programmatically with info from a Http request (creating a survey in-app). I've tried the suggested solutions in <a href="https://stackoverflow.com/questions/7689475/android-checkbox-text-not-displaying">Android Checkbox text not displaying</a> but the text still isn't appearing.</p>
  
  <p>I'm able to create the custom button views, but for some reason the text doesn't display. Any idea where I'm going wrong?</p>
  
  <p>checkbox_selector:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;item android:drawable="@drawable/multiselected" android:state_checked="true"/&gt;
      &lt;item android:drawable="@drawable/multiunselected" android:state_checked="false"/&gt;
  
  &lt;/selector&gt;
  </code></pre>
  
  <p>radio_selector:</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;item android:drawable="@drawable/singleselected" android:state_checked="true"/&gt;
      &lt;item android:drawable="@drawable/singleunselected" android:state_checked="false"/&gt;
  
  &lt;/selector&gt;
  </code></pre>
  
  <p>Here's how I'm creating them:</p>
  
  <pre><code>if (mQuestion != null &amp;&amp; mQuestion.isSingleResponse()
                      &amp;&amp; mAnswerTitles.size() &gt; 0) {
                  for (int i = 0; i &lt; mAnswerTitles.size(); i++) {
                      Answer answer1 = mAnswerTitles.get(i);
                      RadioButton answer = new RadioButton(getActivity());
  
                      answer.setText(answer1.getTitle().toString());
                      answer.setTextSize(24);
                      answer.setTextColor(Color.BLACK);
                      answer.setId(answer1.getId());
                      answer.setButtonDrawable(R.drawable.radio_selector);
                      answer.setLayoutParams(mRadioGroupAnswers.getLayoutParams());
                      answer.setOnClickListener(new View.OnClickListener() {
  
                          @Override
                          public void onClick(View v) {
                              // TODO Auto-generated method stub
                              mNextQuestion.setEnabled(true);
                          }
                      });
                      mRadioGroupAnswers.addView(answer);
                  }
              } else {
                  if (mAnswerTitles != null &amp;&amp; mAnswerTitles.size() &gt; 0) {
                      for (int i = 0; i &lt; mAnswerTitles.size(); i++) {
                          Answer answer1 = mAnswerTitles.get(i);
                          CheckBox answer = new CheckBox(getActivity());
                          answer.setText(answer1.getTitle().toString());
                          answer.setTextSize(24);
                          answer.setTextColor(Color.BLACK);
                          answer.setId(answer1.getId());
                          answer.setButtonDrawable(R.drawable.checkbox_selector);
                          answer.setLayoutParams(mRadioGroupAnswers.getLayoutParams());
                          answer.setOnClickListener(new View.OnClickListener() {
  
                              @Override
                              public void onClick(View v) {
                                  // TODO Auto-generated method stub
                                  mNextQuestion.setEnabled(true);
                              }
                          });
                          if (mAnswerHolder != null) {
                              mAnswerHolder.addView(answer);
                          }
                      }
                  }
  </code></pre>
  
  <p>And the group/layout I'm adding them to:</p>
  
  <pre><code>&lt;RadioGroup
              android:layout_marginTop="8dp"
              android:id="@+id/answerGroup"
              android:textColor="@android:color/black"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" &gt;
          &lt;/RadioGroup&gt;
  
          &lt;LinearLayout
              android:id="@+id/answerTextHolder"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical" &gt;
          &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>It looks like the text is actually just getting hidden by the image - rather than being put on the image and re-sizing the image with the text length:</p>
  
  <p><img src="https://i.stack.imgur.com/Ltdc9.png" alt="enter image description here"></p>