title: How to use RadioGroup in ListView custom adapter?
body: <p>I want to show a single select option in my list. I am using <code>RadioButton</code> in my <code>listView</code> row. I know that <code>RadioGroup</code> is used for single selection.</p>
  <p>But problem is that I have added the <code>RadioButton</code> in my <code>ListRowView</code>. Now I want to add all my list items in one <code>RadioButton</code>. I am using <code>Custom Adapter</code> and in <code>getView()</code>. I get the <code>RadioButton</code> in <code>getView()</code>, but when want to add it in <code>RadioGroup</code> it say</p>
  <blockquote>
  <p>&quot;view already have parent , call removeView() in parent before&quot;</p>
  </blockquote>
  <p>And I know its true, but if I remove it from the view. Then it is not visible.</p>
  <p>I also try to create and add <code>RadioButton</code> programmatically. And then add it in <code>RadioGrop</code>. And then to view of list row. But this time as the parent is <code>RadioGroup</code>, so again it say</p>
  <blockquote>
  <p>&quot;view already have parent , call removeView() in parent before&quot;</p>
  </blockquote>
  <p>What I want to do is to select only one item in list at a time. My code is as follows.</p>
  <h3>getView</h3>
  <pre><code> public class MyAdapter extends ArrayAdapter &lt; MyMenuItem &gt; {
      
      private LayoutInflater mInflater ;
      
      int                    mResource ;
      List &lt; MyMenuItem &gt;    mData ;
      Context context;
      
      public MyAdapter ( Context context , int resource , int textViewResourceId , List &lt; MyMenuItem &gt; data ) {
          super ( context , resource , textViewResourceId , data ) ;
          this.context = context;
          mData = data ;
          mResource = resource ;
          mInflater = ( LayoutInflater ) getSystemService ( Context.LAYOUT_INFLATER_SERVICE ) ;
      }
      
      @ Override
      public View getView ( int position , View convertView , ViewGroup parent ) {
          ViewHolder holder = null ;
          if ( convertView == null ) {
              convertView = mInflater.inflate ( mResource , null ) ;
              holder = new ViewHolder ( ) ;
              holder.icon = ( ImageView ) convertView.findViewById ( R.id.icon ) ;
              holder.text = ( TextView ) convertView.findViewById ( R.id.text ) ;
              holder.comment = ( TextView ) convertView.findViewById ( R.id.comment ) ;
              LinearLayout lin = ( LinearLayout ) convertView.findViewById ( R.id.linerList ) ;
              RadioButton rbtn = new RadioButton ( context );
              LayoutParams lparam = new LayoutParams ( LayoutParams.WRAP_CONTENT , LayoutParams.WRAP_CONTENT );
              rbtn.setSelected ( false );
              holder.check = rbtn;
              //radioGroup.addView ( rbtn );
              lin.addView ( rbtn , 0 );
              
              convertView.setTag ( holder ) ;
          } else {
              holder = ( ViewHolder ) convertView.getTag ( ) ;
          }
          
          holder.text.setText ( mData.get ( position ).getText ( ) ) ;
          holder.comment.setText ( mData.get ( position ).getComment ( ) ) ;
          
          holder.icon.setImageResource ( getApplicationContext ( ).getResources ( ).getIdentifier ( mData.get ( position ).getIcon ( ) ,
                  &quot;drawable&quot; , getPackageName ( ) )
  
          ) ;
          
          return convertView ;
      }
      
  }
  </code></pre>
  <p>My XML for the row</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;?android:attr/listPreferredItemHeight&quot;
  android:padding=&quot;6dip&quot;&gt;
  &lt;LinearLayout
      android:id = &quot;@+id/linerList&quot;
      android:orientation=&quot;horizontal&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;&gt;
      &lt;ImageView
          android:id=&quot;@+id/icon&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginRight=&quot;6dip&quot; /&gt;
  &lt;/LinearLayout&gt;
  &lt;LinearLayout
      android:orientation=&quot;vertical&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_weight=&quot;1&quot;
      android:layout_height=&quot;fill_parent&quot;&gt;
      &lt;TextView
          android:id=&quot;@+id/text&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_weight=&quot;1&quot;
          android:gravity=&quot;center_vertical&quot;
          android:text=&quot;My Application&quot;
          android:textSize=&quot;20sp&quot;
          android:singleLine=&quot;true&quot;
          android:ellipsize=&quot;marquee&quot;
          android:textColor=&quot;@color/white&quot; /&gt;
      &lt;TextView
          android:id=&quot;@+id/comment&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_weight=&quot;1&quot;
          android:singleLine=&quot;true&quot;
          android:ellipsize=&quot;marquee&quot;
          android:text=&quot;Simple application that shows how to use RelativeLayout&quot;
          android:textSize=&quot;14sp&quot;
          android:textColor=&quot;@color/light_gray&quot; /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/TYwao.png" alt="It look like this if I not use RadioGroup" /></p>