title: how to attach a listener to a radio button
body: <p>I have an activity that displays various radiobuttons. The radiobuttons are grouped in radiogroups. I want some of the radiobutton to disappear when a certain radiobutton is checked. eg when the incident button is checked the fall, trip and illness radiobutton disappear. how can i achieve this?</p>
  
  <p>I have the foolowing code but need to somehow attach a listener to the incident button.</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.reportsomethinglayout);
  
           resolution = (EditText)findViewById(R.id.editTextresolution);
          // resolution.setInputType(InputType.TYPE_NULL);
          // showSoftKeyboard(resolution);
  
  
  
           accident  = (RadioButton)findViewById(R.id.radioButtonaccident);
           incident  = (RadioButton)findViewById(R.id.radioButtonincident);
           concern  = (RadioButton)findViewById(R.id.radioButtonconcern);
           fall  = (RadioButton)findViewById(R.id.radioButtonfall);
           trip  = (RadioButton)findViewById(R.id.radioButtonTrip);
           illness  = (RadioButton)findViewById(R.id.radioButtonillness);
  
  
  
  
  
      }
  
  
  
       public void onRadioButtonClicked(View view) {
              // Is the button now checked?
              boolean checked = ((RadioButton) view).isChecked();
  
              // Check which radio button was clicked
              switch(view.getId()) {
                  case R.id.radioButtonaccident:
                      if (checked)
                          Log.e(TAG, "accident radiobutton checked");
                      break;
                  case R.id.radioButtonincident:
                      if (checked)
                          Log.e(TAG, "incident radiobutton checked");
  
                              fall.setVisibility(View.GONE);
                              trip.setVisibility(View.GONE);
                              illness.setVisibility(View.GONE);
                      break;
              }
          }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="@drawable/carefreebgscaledalphajpg" &gt;
  &lt;ScrollView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
     &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:id="@+id/linearlayoutasscrollneedsonenamedchild" &gt;
  &lt;TextView
          android:id="@+id/reportsomethingtitletextview"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Carer Reporting"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:layout_gravity="center" /&gt;
  
  
         &lt;TextView
          android:id="@+id/textViewcategory"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Category" /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal" &gt;
  
       &lt;RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"&gt;   
  
  
       &lt;RadioButton
          android:id="@+id/radioButtonaccident"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Accident" /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButtonincident"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Incident" /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButtonconcern"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Concern" /&gt;
  
      &lt;/RadioGroup&gt;
  
  
      &lt;/LinearLayout&gt;
  
      &lt;TextView
          android:id="@+id/textViewspacer"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="" /&gt;
  
  
      &lt;TextView
          android:id="@+id/textViewtype"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Type" /&gt;
  
       &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal" &gt;
  
          &lt;RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"&gt;   
  
       &lt;RadioButton
          android:id="@+id/radioButtonfall"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Fall" /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButtonTrip"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Trip" /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButtonillness"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Illness" /&gt;
  
      &lt;/RadioGroup&gt;
  
      &lt;/LinearLayout&gt;
  
       &lt;TextView
          android:id="@+id/textViewspacer2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="" /&gt;
  
  
      &lt;TextView
          android:id="@+id/textViewaction"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Action" /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal" &gt;
  
          &lt;RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"&gt;
  
       &lt;RadioButton
          android:id="@+id/radioButtonCallDoctor"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Call Doctor" /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButtoncalledkin"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Called next of kin" /&gt;
  
  
  
      &lt;/RadioGroup&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;TextView
          android:id="@+id/textViewspacer3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="" /&gt;
  
  
      &lt;TextView
          android:id="@+id/textViewresolution"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="Resolution" /&gt;
  
      &lt;EditText
          android:id="@+id/editTextresolution"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="1"
          android:lines="8"
          android:inputType="textMultiLine"
           &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;Button
          android:id="@+id/buttonsubmit"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:text="Submit" /&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt; 
  &lt;/LinearLayout&gt;
  </code></pre>