title: Radio button to get a simple tab effect in android
body: <h2>How to create a setting such that there are two radiobuttons on the layout</h2>
  
  <p>I have made a better representation from my last question</p>
  
  <p><strong>Radio buttons</strong></p>
  
  <ul>
  <li>RadioButton1 </li>
  <li>RadioButton2</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/243jU.png" alt="enter image description here"></p>
  
  <hr>
  
  <p>Click on <code>RadioButton1</code> .. <code>Activity1</code> should display on the <code>same screen</code></p>
  
  <p>Click on <code>RadioButton1</code> again <code>Activity2</code> should display on the <code>same screen</code></p>
  
  <p>similarly to RadioButton2</p>
  
  <hr>
  
  <p>This i have performed using tabs with tabhost</p>
  
  <p>Since the design of tabhost is rigid ..... is it possible to make as above</p>
  
  <hr>
  
  <p><strong>If so, How can it be done ....?</strong></p>
  
  <h2>{edit}</h2>
  
  <p>I didnt know how to use radiobutton but i have tried something similar</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
          }
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.layout.activity_main, menu);
              return true;
          }
  
      }
  </code></pre>
  
  <p><strong>Fragment_1.java</strong></p>
  
  <pre><code>public class Fragment_1 extends Fragment{
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
              // TODO Auto-generated method stub      
  
              View view = inflater.inflate(R.layout.fragment_fragment_1, container, false);
  
              final EditText edtxtPersonName_Fragment = (EditText) view.findViewById(R.id.edtxtPersonName);
              Button btnSayHi_Fragment = (Button) view.findViewById(R.id.btnSayHi);
  
              btnSayHi_Fragment.setOnClickListener(new OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
  
                      String name = edtxtPersonName_Fragment.getText().toString();
  
                      FragmentManager fm = getFragmentManager();
                      Fragment_2 f2 = (Fragment_2) fm.findFragmentById(R.id.fragment_content_2);
  
                      if(f2 != null &amp;&amp; f2.isInLayout())
                      {
                          f2.setName(name);
                      }
  
                      Activity activity = getActivity();
  
                      if(activity != null)
                      {
                          Toast.makeText(activity, "Say&amp;ing Hi in Progress...", Toast.LENGTH_LONG).show();
                      }
                  }
              });
  
              return view;
  
  
          }
  
      }
  </code></pre>
  
  <p><strong>Fragment_2.java</strong></p>
  
  <pre><code>public class Fragment_2 extends Fragment {
  
      View view;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // TODO Auto-generated method stub
  
          view = inflater.inflate(R.layout.fragment_fragment_2, container, false);        
          return view;
      }
  
      public void setName(String name)
      {
          TextView txtName = (TextView) view.findViewById(R.id.txtViewResult);
          txtName.setText("Hi " + name);
      }
  
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
  
      &lt;fragment
          android:id="@+id/fragment_content_1"
          android:name="com.example.fragmentexample.Fragment_1"
          android:layout_width="0dip"
          android:layout_weight="0.50"
          android:layout_height="fill_parent" &gt;
      &lt;/fragment&gt;
  
      &lt;fragment
          android:id="@+id/fragment_content_2"
          android:name="com.example.fragmentexample.Fragment_2"
          android:layout_width="0dip"
          android:layout_weight="0.50"
          android:layout_height="fill_parent" &gt;
  
          &lt;!-- Preview: layout=@layout/fragment_basic --&gt;
      &lt;/fragment&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Still i got log errors</p>
  
  <p><strong>LOG::</strong></p>
  
  <pre><code>10-13 15:56:44.837: D/AndroidRuntime(326): Shutting down VM
  10-13 15:56:44.837: W/dalvikvm(326): threadid=1: thread exiting with uncaught exception (group=0x40015560)
  10-13 15:56:45.117: E/AndroidRuntime(326): FATAL EXCEPTION: main
  10-13 15:56:45.117: E/AndroidRuntime(326): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragment/com.example.fragment.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.os.Handler.dispatchMessage(Handler.java:99)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.os.Looper.loop(Looper.java:123)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at java.lang.reflect.Method.invokeNative(Native Method)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at java.lang.reflect.Method.invoke(Method.java:507)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at dalvik.system.NativeStart.main(Native Method)
  10-13 15:56:45.117: E/AndroidRuntime(326): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.Activity.setContentView(Activity.java:1657)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at com.example.fragment.MainActivity.onCreate(MainActivity.java:16)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  10-13 15:56:45.117: E/AndroidRuntime(326):  ... 11 more
  10-13 15:56:45.117: E/AndroidRuntime(326): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.fragment-1.apk]
  10-13 15:56:45.117: E/AndroidRuntime(326):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.createView(LayoutInflater.java:471)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
  10-13 15:56:45.117: E/AndroidRuntime(326):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
  10-13 15:56:45.117: E/AndroidRuntime(326):  ... 20 more
  10-13 15:56:49.207: I/Process(326): Sending signal. PID: 326 SIG: 9
  </code></pre>