title: Custom Layout RadioButton Android
body: <p>I have a problem with a customization of RadioButton Widget in Android.
  I need a RadioButton with an icon and a single line text under the icon. 
  Aspect like at bottom bar in iOS, with icon and text checked in different color.
  I have created a Custom class the extends RadioButton and inflate my layout.</p>
  
  <p>The widget work fine, but don't show my layout, it show only a background, not imageView and textView.
  Any idea?</p>
  
  <p>Thanks in advances</p>
  
  <pre><code>public class RadioButtonImageToggle extends RadioButton {
  
  private Drawable imageNormalState, imageCheckedState;
  private ImageView imageView;
  private TextView textViewTitle;
  
  public RadioButtonImageToggle(Context context, AttributeSet attrs, int defStyleAttr) {
      super(context, attrs, defStyleAttr);
      initViews(context,attrs, defStyleAttr);
  }
  
  public RadioButtonImageToggle(Context context, AttributeSet attrs) {
      super(context, attrs);
      initViews(context, attrs, 0);
  }
  
  
  private void initViews(Context context, AttributeSet attrs, int defStyle) {
  
  
      TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RadioButtonImageToggle, defStyle, R.style.Widget_Holo_RadioImageToggle);
  
      try {
          // get the text and colors specified using the names in attrs.xml
          imageNormalState = a.getDrawable(R.styleable.RadioButtonImageToggle_imageNormalState);
          imageCheckedState = a.getDrawable(R.styleable.RadioButtonImageToggle_imageCheckedState);
      } finally {
          a.recycle();
      }
      LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View view = layoutInflater.inflate(R.layout.radio_image_toggle, null);
  
      imageView = (ImageView) view.findViewById(R.id.iconToggle);
      textViewTitle = (TextView) view.findViewById(R.id.textViewTitle);
  
      imageView.setImageDrawable(imageNormalState);
      textViewTitle.setText(getText());
  }
  
  @Override
  public void toggle()
  {
      if(isChecked()) {
          imageView.setImageDrawable(imageCheckedState);
          if(getParent() instanceof RadioGroup) {
             ((RadioGroup)getParent()).clearCheck();
          }
      } else {
          imageView.setImageDrawable(imageNormalState);
          setChecked(true);
      }
  }
  </code></pre>
  
  <p>Layout custom is:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;ImageView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:id="@+id/iconToggle"
      android:layout_gravity="center"
      android:src="@mipmap/ic_launcher" /&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="?android:attr/textAppearanceSmall"
      android:text="TITLE"
      android:id="@+id/textViewTitle"
      android:layout_gravity="center"
      android:lines="1"
      android:singleLine="true" /&gt;
  </code></pre>
  
  <p></p>