title: How to use Radio button group id for switch, in Android, between different fragments
body: <p>I am a newbie.</p>
  
  <p>Using navigation bar, fragments in the app.</p>
  
  <p><strong>Files description:</strong></p>
  
  <p><strong>fragment_settings.xml:</strong> Contains radio button group</p>
  
  <p><strong>SettingsFragment.java:</strong> Basically to show the fragment_settings.xml, when Settings is clicked in the navigation drawer. I have checked different</p>
  
  <p><strong>MainFragment.java:</strong> Here, <strong>I want to use the RadioButton id, which is clicked into the switch case</strong> and then perform operations accordingly.</p>
  
  <p>But the problem is control is coming in the switch but not in the cases, I tried by putting toast but the id is not matching to any case.</p>
  
  <p><strong>fragment_settings.xml</strong></p>
  
  <pre><code>    &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      tools:context="com.threefriends.filecrypto.SettingsFragment"&gt;
  
      &lt;!-- TODO: Update blank fragment layout --&gt;
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"&gt;
  
          &lt;TextView
              android:id="@+id/textview2"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Choose algorithm:"
              android:textSize="18dp"
              android:layout_marginLeft="10dp"
              android:layout_marginTop="71dp"
          /&gt;
          &lt;RadioGroup
              android:id="@+id/radioAlgorithms"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"&gt;
  
              &lt;RadioButton
                  android:id="@+id/radioaes"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="AES (Default)"
                  android:checked="true"
                  android:layout_marginLeft="5dp"
              /&gt;
              &lt;RadioButton
                  android:id="@+id/radiodes"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="DES"
                  android:layout_marginLeft="5dp"
                  /&gt;
              &lt;RadioButton
                  android:id="@+id/radioidea"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="IDEA"
                  android:layout_marginLeft="5dp"
              /&gt;
              &lt;RadioButton
                  android:id="@+id/radiocustom"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Custom"
                  android:layout_marginLeft="5dp"
                  /&gt;
          &lt;/RadioGroup&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p><strong>SettingsFragment.java</strong></p>
  
  <pre><code>    package com.threefriends.filecrypto;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.Toast;
  
  
  public class SettingsFragment extends Fragment
  {
  
  
      public SettingsFragment() {
          // Required empty public constructor
      }
  
  
      RadioGroup radiogroup;
      RadioButton aes, des, idea, custom;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
      {
  
          View view=inflater.inflate(R.layout.fragment_settings, container, false);
          // Inflate the layout for this fragment
          //return inflater.inflate(R.layout.fragment_settings, container, false);
          return view;
      }
  }
  </code></pre>
  
  <p><strong>MainFragment.java</strong></p>
  
  <pre><code> public class MainFragment extends Fragment {
      SettingsFragment settingsfragment;
  
      //Defined for file edittext.
      EditText editText2;
  
      public MainFragment() {
          // Required empty public constructor
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_main, container, false);
         });
          final int id = ((RadioGroup)view.findViewById(R.id.radioAlgorithms)).getCheckedRadioButtonId();
          final Button b2 = (Button) view.findViewById(R.id.encb);    //Encrypt Button
          Button b3 = (Button) view.findViewById(R.id.decb);      //Decrypt Button
  
          b2.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(getActivity().getApplicationContext(), "Starting..."+R.id.radioAlgorithms, Toast.LENGTH_SHORT).show();
                  // click related code goes here
                  switch(id)    //This id is not matching to any case.
                  {
                      case R.id.radioaes: {
                                 //Code for aes algorithm.
                                 break;
                      case R.id.radiodes: {
                                 //Code for des algorithm.
                                 break;
                       }
                      case R.id.radioidea: {
                                 //Code for idea algorithm.
                                 break;
                      }
                      case R.id.radiocustom: {
                                  //My custom algorithm code.
                                  break;
                      }
                  }
  }
          });
  </code></pre>