title: Using CheckBox's with button and switch
body: <p>I am trying to show toast with the color name of the CheckBox that selected, but when I click on the button, nothing happens, I tried to use the LinearLayout as a parent of all views to get the id of the chosen Checkbox, first I tried to create it as a Linearlayout in main activity but the app is stopped when I choose one checkbox and click on the button, then I changed it to a View and cast it to LinearLayout</p>
  <p>here's my code</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          View view = (LinearLayout)findViewById(R.id.view);
  
          Button btn = findViewById(R.id.button1);
  
          CheckBox chk1 = findViewById(R.id.chk1);
          CheckBox chk2 = findViewById(R.id.chk2);
          CheckBox chk3 = findViewById(R.id.chk3);
  
          btn.setOnClickListener(v -&gt; {
  
              switch (view.getId()) {
                  case R.id.chk1:
                      if (chk1.isChecked())
                          Toast.makeText(MainActivity.this, &quot;Green&quot;, Toast.LENGTH_LONG).show();
                      break;
  
                  case R.id.chk2:
  
                      if (chk2.isChecked())
                          Toast.makeText(MainActivity.this, &quot;Orange&quot;, Toast.LENGTH_LONG).show();
                      break;
  
                  case R.id.chk3:
                      if (chk3.isChecked())
                          Toast.makeText(MainActivity.this, &quot;Orange&quot;, Toast.LENGTH_LONG).show();
  
                      break;
                  default:
              }
          });
  
      }
  </code></pre>
  <p><strong>The layout</strong></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;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot;
      tools:context=&quot;.MainActivity&quot;
      android:id=&quot;@+id/view&quot;
      &gt;
  
      &lt;TextView
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;16dp&quot;
          android:layout_gravity=&quot;center&quot;
          android:text=&quot;@string/app_name&quot;
          android:textColor=&quot;@color/black&quot;
          android:textAlignment=&quot;center&quot;
          android:textSize=&quot;24sp&quot;
          /&gt;
  
      &lt;CheckBox
          android:id=&quot;@+id/chk1&quot;
          android:text=&quot;Green&quot;
          android:textSize=&quot;33sp&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          &gt;
  
      &lt;/CheckBox&gt;
  
      &lt;CheckBox
          android:id=&quot;@+id/chk2&quot;
          android:text=&quot;Orange&quot;
          android:textSize=&quot;33sp&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          &gt;
  
      &lt;/CheckBox&gt;
  
      &lt;CheckBox
          android:id=&quot;@+id/chk3&quot;
          android:text=&quot;Blue&quot;
          android:textSize=&quot;33sp&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          &gt;
  
      &lt;/CheckBox&gt;
  
      &lt;Button
          android:id=&quot;@+id/button1&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;16dp&quot;
          android:layout_gravity=&quot;center&quot;
          android:text=&quot;@string/button1&quot;
          android:textAllCaps=&quot;false&quot;
          android:textSize=&quot;24sp&quot;
          &gt;
  
      &lt;/Button&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>