title: Set-and-swipe Forms using Android Fragments
body: <p>I am trying to develop a very simple Android app for rapid data collection, where an activity displays a fragment containing a form with a number of RadioGroup elements.  I would like to have the user be able to quickly tap out the radio selections, then be able to swipe the form to the right to dispose of the fragment, record the data, and bring up another empty form.</p>
  
  <p>What I can't figure out is how to set up the "swipe and replace" feature.  I'm thinking of something similar to the ViewPager support class, except no scrolling backwards and an unlimited number of pages.  What classes can I use to achieve this kind of behavior?  Here's my stripped-down code:</p>
  
  <p><strong>fragment_record.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/mainScrollView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior" &gt;
  
      &lt;LinearLayout 
          android:id="@+id/mainLinearLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Group 1"
              android:id="@+id/textView" /&gt;
  
          &lt;RadioGroup
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:id="@+id/Group1"&gt;
  
              &lt;!-- Radio Buttons /--&gt;
          &lt;/RadioGroup&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Group 2"
              android:id="@+id/textView2" /&gt;
  
          &lt;RadioGroup
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:id="@+id/Group2"&gt;
  
              &lt;!-- Radio Buttons /--&gt;
          &lt;/RadioGroup&gt;
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p><strong>RecordFragment.java:</strong></p>
  
  <pre><code>import android.app.Fragment;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class RecordFragment extends Fragment {
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_record, container, false);
          return view;
      }
  
  }
  </code></pre>
  
  <p><strong>activity_record.xml</strong></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:id="@+id/fragment_container" &gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p><strong>RecordActivity.java</strong></p>
  
  <pre><code>import android.app.Activity;
  import android.app.Fragment;
  import android.os.Bundle;
  import android.view.View;
  
  public class RecordActivity extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_record);
  
          if (findViewById(R.id.fragment_container) != null) {
              if (savedInstanceState != null) return;
              RecordFragment theFragment = new RecordFragment();
              theFragment.setArguments(getIntent().getExtras());
              getFragmentManager().beginTransaction().add(R.id.fragment_container, theFragment).commit();
          }
      }
  }
  </code></pre>