title: Android Material Button Toggle Group
body: <p>I'm creating a form in android which asks for gender. To get this input I use Material Button Toggle Group which contains two buttons. I don't know how to know which button is clicked in my activity.java. How to get to know about the selected button in my activity so that i can save the details in different database.</p>
  
  <p><strong>myxml.xml</strong></p>
  
  <pre><code>    &lt;com.google.android.material.button.MaterialButtonToggleGroup
                  android:id="@+id/toggleButton"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  app:singleSelection="true"&gt;
                  &lt;Button
                      android:id="@+id/button1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Male"
                      android:layout_marginStart="5dp"
                      style="?attr/materialButtonOutlinedStyle"/&gt;
                  &lt;Button
                      android:id="@+id/button2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Female"
                      android:layout_marginStart="10dp"
                      style="?attr/materialButtonOutlinedStyle"/&gt;
  
              &lt;/com.google.android.material.button.MaterialButtonToggleGroup&gt;
  </code></pre>
  
  <p><strong>Myactivity.java</strong></p>
  
  <pre><code>    MaterialButtonToggleGroup toggleButton = findViewById(R.id.toggleButton);
      toggleButton.addOnButtonCheckedListener(); 
      // I CAN'T FIND ANY PROPER SOLUTION
  </code></pre>