title: How do I make my toggle button act like a radio button?
body: <p>I have 2 toggle buttons in my code and I want to change the behavior such that when one is selected the other one is not and vice versa. (want it to work like a radio button ).Any idea on how I can go about it?
  Here's my java code for the same: </p>
  
  <pre><code>public class DashboardManageListFragment extends Fragment implements OnClickListener,OnCheckedChangeListener {
  
      public final static String TAG_MANAGE_DASHBOARD_LIST_FRAGMENT = "ManageDashboardListFragment";
      public final static String IS_PERSONAL = "IsPersonal";
      public final static String IS_SHARED = "IsShared";
      public static final String ANIMATION = "animation";
      private boolean mShouldbeon;
      private boolean mInitialShouldbeon;
      protected Button mPreferencesDoneButton;
  
  
  
  
      public static DashboardManageListFragment newInstance(final FragmentManager manager, final boolean isPersonal) {
          final DashboardManageListFragment fragment = new DashboardManageListFragment();
          final FragmentInfo fragmentInfo = new FragmentInfo(TransactionMethods.ADD, R.id.fragment_container);
          fragmentInfo.setFragmentTag(TAG_MANAGE_DASHBOARD_LIST_FRAGMENT);
          Bundle bundle = new Bundle();
          bundle.putBoolean(IS_PERSONAL, isPersonal);
          fragment.setArguments(bundle);
          fragmentInfo.setAnimation(R.anim.no_animation, R.anim.no_animation);
          fragmentInfo.setPopAnimation(R.anim.no_animation, R.anim.no_animation);
          FragmentStackManager.getInstance().transitionFragment(manager, fragment, fragmentInfo);
  
          return fragment;
      }
  
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_manage_lists, container, false);
  
          getArguments().getBoolean(IS_PERSONAL, true);
  
          final Bundle arguments = getArguments();
          final int animation = arguments.getInt(ANIMATION, 0);
          final ManageListDashboardActivity activity = (ManageListDashboardActivity) getActivity();
          /*if(!personalToggle.isChecked()){
          view.findViewById(R.id.personal_list_toggle_control).setVisibility(View.GONE);
          }*/
          return view;
      }
      protected void setupClickListeners() {
          mPreferencesDoneButton = (Button) getActivity().findViewById(R.id.button_done);
          Typeface face = Typeface.createFromAsset(mPreferencesDoneButton.getContext().getAssets(),
                  "fonts/proxima-nova-regular.ttf");
          mPreferencesDoneButton.setTypeface(face);
          mPreferencesDoneButton.setOnClickListener(this);
          mPreferencesDoneButton.setEnabled(((ManageListDashboardActivity) getActivity()).isDoneButtonEnabled());
      }
  
      @Override
      public void onStart() {
          super.onStart();
          setupClickListeners();
          final ToggleButton personalToggle = (ToggleButton) getView().findViewById(R.id.personal_list_toggle_control);
          personalToggle.setOnCheckedChangeListener(this);
  
          final ToggleButton sharedToggle = (ToggleButton) getView().findViewById(R.id.shared_list_toggle_control);
          sharedToggle.setOnCheckedChangeListener(this);
  
          if(personalToggle.isChecked() == true){
          }else{
              //getActivity().findViewById(R.id.personal_list_toggle_control).setVisibility(View.GONE);
              sharedToggle.isChecked();
          }
          if(sharedToggle.isChecked()){
  
              }else{
                  //getActivity().findViewById(R.id.shared_list_toggle_control).setVisibility(View.GONE);
                  personalToggle.isChecked();
              }
  
      }
  
  
  
      @Override
      public void onClick(final View view) {
  
          final ManageListDashboardActivity activity = (ManageListDashboardActivity) getActivity();
  
          switch (view.getId()) {
          case R.id.button_personal_list:
              return;
  
          case R.id.button_shared_list:
              return;
  
  
          case R.id.button_done:
              break;
  
          default:
              break;
      }
  
      activity.onBackPressed();
  
  
      }
      protected void toggleDoneButton() {
          boolean isUserPreferencesUpdated = SharedPreferencesManager.getInstance().isUserPreferencesUpdated();
          boolean isDoneEnabled = (
                   mShouldbeon != mInitialShouldbeon
                  || isUserPreferencesUpdated);
          mPreferencesDoneButton.setEnabled(isDoneEnabled);
      }
  
  
  
      @Override
      public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
          switch (buttonView.getId()) {
              case R.id.shared_list_toggle_control:
                  mShouldbeon = isChecked;
                  break;
              case R.id.personal_list_toggle_control:
                  mShouldbeon = isChecked;
                  break;
  
              default:
                  break;
          }
          toggleDoneButton();
      }
  </code></pre>
  
  <p>Here's the corresponding xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/altercolor2" &gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/altercolor2"
          android:orientation="vertical" &gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content" &gt;
  
              &lt;Button
                  android:id="@+id/button_personal_list"
                  android:layout_width="match_parent"
                  android:layout_height="@dimen/manage_news_btn_ht"
                  android:layout_marginLeft="2dp"
                  android:layout_marginRight="2dp"
                  android:background="@drawable/manage_market_category_btnbg"
                  android:gravity="left|center_vertical"
                  android:paddingLeft="@dimen/frequent_padding_left"
                  android:text="@string/personal"
                  android:textColor="#cccccc"
                  android:textSize="@dimen/title" /&gt;
  
  
  
             &lt;ToggleButton
          android:id="@+id/personal_list_toggle_control"
          style="@style/Button.Toggle"
          android:layout_width="@dimen/toggle_width_ht"
          android:layout_height="@dimen/toggle_width_ht"
          android:layout_alignParentRight="true"
           android:layout_centerVertical="true"
          android:layout_marginRight="10dp"
          android:paddingTop="0dp"
         /&gt;
  
          &lt;/RelativeLayout&gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content" &gt;
  
              &lt;Button
                  android:id="@+id/button_shared_list"
                  android:layout_width="match_parent"
                  android:layout_height="@dimen/manage_news_btn_ht"
                  android:layout_marginLeft="2dp"
                  android:layout_marginRight="2dp"
                  android:background="@drawable/manage_market_category_btnbg"
                  android:gravity="left|center_vertical"
                  android:paddingLeft="@dimen/frequent_padding_left"
                  android:text="@string/shared"
                  android:textColor="#cccccc"
                  android:textSize="@dimen/title" /&gt;
  
  
  
             &lt;ToggleButton
          android:id="@+id/shared_list_toggle_control"
          style="@style/Button.Toggle"
          android:layout_width="@dimen/toggle_width_ht"
          android:layout_height="@dimen/toggle_width_ht"
          android:layout_alignParentRight="true"
           android:layout_centerVertical="true"
          android:layout_marginRight="10dp"
          android:paddingTop="0dp"
         /&gt;
  
          &lt;/RelativeLayout&gt;
  
  
  
      &lt;/LinearLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>So, when personal lists is selected I want shared lists checkbox to be invisible and vice versa.</p>