title: Android: Radio button in custom list view
body: <p>I am developing an application in which I need to implement radio buttons in list view. I want to implement a list view having one radio button and two text views in each row. And one button &quot;Ok&quot; below listview.</p>
  <p>What I have done is created a list view and a custom adapter.
  The code of listview is as:</p>
  <pre><code>&lt;ListView
      android:id=&quot;@+id/listview&quot;
      android:layout_width=&quot;fill_parent&quot;
      android:layout_height=&quot;fill_parent&quot;
      android:cacheColorHint=&quot;#00000000&quot;
      android:overScrollMode=&quot;never&quot;
      tools:ignore=&quot;NestedScrolling&quot;
      android:choiceMode=&quot;singleChoice&quot; &gt;
  &lt;/ListView&gt;
  </code></pre>
  <p>And I created a custom adapter layout as:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;TableLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;fill_parent&quot;
      android:layout_height=&quot;fill_parent&quot; &gt;
  
      &lt;TableRow
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          tools:ignore=&quot;UselessParent&quot; &gt;
  
          &lt;RadioButton
              android:id=&quot;@+id/radiobutton&quot;
              android:layout_width=&quot;0sp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_weight=&quot;.1&quot; /&gt;
  
          &lt;TextView
              android:id=&quot;@+id/textview1&quot;
              android:layout_width=&quot;0sp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_weight=&quot;.3&quot; /&gt;
  
          &lt;TextView
              android:id=&quot;@+id/textview2&quot;
              android:layout_width=&quot;0sp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_weight=&quot;.3&quot; /&gt;
  
      &lt;/TableRow&gt;
  
  &lt;/TableLayout&gt;
  </code></pre>
  <p>The java code of fragment is as follows:</p>
  <pre><code>ListView listView = (ListView) view.findViewById(R.id.listview);
  
  // values is a StringArray holding some string values.
  CustomAdapter customAdapter = new CustomAdapter (getActivity(), values);
  listView.setAdapter(customAdapter );
  listView.setOnItemClickListener(this);
  
  @Override
  public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) {}
  </code></pre>
  <p>And the code of the adapter is as follows:</p>
  <pre><code>public class CustomAdapter extends ArrayAdapter&lt;String&gt; {   
      /** Global declaration of variables. As there scope lies in whole class. */
      private Context context;
      private String[] listOfValues;
  
      /** Constructor Class */
      public CustomAdapter (Context c,String[] values) {
          super(c,R.layout.adapter_layout,values);
          this.context = c;
          this.listOfValues = values;
      }
  
      /** Implement getView method for customizing row of list view. */
      public View getView(final int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = ((Activity)context).getLayoutInflater();
          // Creating a view of row.
          View rowView = inflater.inflate(R.layout.adapter_layout, parent, false);
              
              TextView textView1 = (TextView)rowView.findViewById(R.id.textview1);
              TextView textView2 = (TextView)rowView.findViewById(R.id.textview2);
  
              RadioButton radioButton = (RadioButton) rowView.findViewById(R.id.radiobutton);
  
              radioButton.setOnClickListener(new OnClickListener() {          
              @Override   
              public void onClick(View v) {
                  Toast.makeText(context, CustomAdapter[position], Toast.LENGTH_SHORT).show();
              }
          });
      
          return review;
      }
  }    
  </code></pre>
  <p>The data of textview1 are populated from SQLite database and on textview2 the data are &quot;Status Closed&quot;. And on the selection of or by clicking any radio button the text of text view gets changed to &quot;Status Open&quot;.</p>
  <p><strong>The Issue is:</strong> The need of application is that only one radio button should get selected and data of textview2 get a change on selection. And when the user clicks on the other radio button it gets select and the previous one should get deselect and the text of textview2 gets changed to &quot;Status Closed&quot; of a previously selected radio button and clicked radio button to &quot;Status Open&quot;.</p>
  <p><strong>Edit 1:</strong></p>
  <p>And click on the &quot;OK&quot; button I want to get the position, text of list view textview1, and textview2, as I want to save that text in SQLite database in the review.</p>
  <p>Please guide me on what steps should I follow. I am in the middle of my application. Your valuable guidance is required.</p>