title: How to pass data from date picker and spinner to another activity
body: <p>I'm a beginning android developer. </p>
  
  <p>I need to pass data from two date pickers and a spinner to another activity.</p>
  
  <p>Can some one help me with this code:</p>
  
  <pre><code>package qi.com;
  import java.text.DateFormat;
  import java.util.Calendar;
  
  import android.app.Activity;
  import android.app.DatePickerDialog;
  import android.app.DatePickerDialog.OnDateSetListener;
  import android.app.Dialog;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.DatePicker;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  
  //multi date input
  public class CoaActivity extends Activity implements AdapterView.OnItemSelectedListener {
      TextView selection;
      TextView mDateStart;
      TextView mDateEnd;
      Button mPickStart;
      Button mPickEnd;
      Calendar startDate;
      Calendar EndDate;
      int mYear;
      int mMonth;
      int mDay;
  
      //list menu
      String[] items = {"Pendapatan","Biaya"};
  
      static final int DATE_DIALOG_ID = 0;
  
      private TextView activeDateDisplay;
      private Calendar activeDate;
  
  
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          //display to text view from list View
          selection = (TextView) findViewById(R.id.selection);
          Spinner spin= (Spinner) findViewById(R.id.spinner);
          spin.setOnItemSelectedListener(this);
  
          ArrayAdapter&lt;String&gt; aa= new ArrayAdapter&lt;String&gt; (this, android.R.layout.simple_spinner_item, items);
          aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spin.setAdapter(aa);
  
          //capture view elements
          mDateStart = (TextView) findViewById(R.id.DateStar);
          mPickStart = (Button) findViewById(R.id.btn_PickDateStart);
  
          //current date
          startDate = Calendar.getInstance();
  
          //listener click button
          mPickStart.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  showDateDialog(mDateStart, startDate);
              }
          });
  
          //END Date
          mDateEnd = (TextView) findViewById(R.id.DateEnd);
          mPickEnd = (Button) findViewById(R.id.btn_PickDateEnd);
  
          EndDate = Calendar.getInstance();
  
          //listener click button
          mPickEnd.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  showDateDialog(mDateEnd, EndDate);
              }
          });
  
  
          //display current date
          updateDisplay(mDateStart, startDate);
          updateDisplay(mDateEnd, EndDate);
  
          //Detail("tes");
  
      }
  
      private void updateDisplay(TextView dateDisplay, Calendar date) {
          dateDisplay.setText(
                  new StringBuilder()
                      // Month is 0 based so add 1
                      //.append(date.get(Calendar.DAY_OF_MONTH)).append("-")
                      .append(date.get(Calendar.DATE)).append("-")
                      .append(date.get(Calendar.MONTH) + 1).append("-")
                      .append(date.get(Calendar.YEAR)).append(" "));
  
                  //.append(DateFormat.getDateInstance(Calendar.MONTH)));
  
      }
  
      public void showDateDialog(TextView dateDisplay, Calendar date) {
          activeDateDisplay = dateDisplay;
          activeDate = date;
          showDialog(DATE_DIALOG_ID);
      }
  
  
      private OnDateSetListener dateSetListener = new OnDateSetListener() {
          @Override
          public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
              activeDate.set(Calendar.YEAR, year);
              activeDate.set(Calendar.MONTH, monthOfYear);
              //activeDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
              activeDate.set(Calendar.DATE, dayOfMonth);
              updateDisplay(activeDateDisplay, activeDate);
              unregisterDateDisplay();
  
  
          }
      };
  
  
  
  
      private void unregisterDateDisplay() {
          activeDateDisplay = null;
          activeDate = null;
      }
  
      protected Dialog onCreateDialog(int id) {
          switch (id) {
              case DATE_DIALOG_ID:
  
                  return new DatePickerDialog(this, dateSetListener, activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DATE));
          }
          return null;
      }
  
      protected void onPrepareDialog(int id, Dialog dialog) {
          super.onPrepareDialog(id, dialog);
          switch (id) {
              case DATE_DIALOG_ID:
                  ((DatePickerDialog) dialog).updateDate(activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DATE));
                  break;
          }
      }
  
      public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int position, long id) {
          selection.setText(items[position]);
  
          Intent grid=new Intent(this, Grid.class);
          this.startActivity(grid);
  
          //send to another activity
          //Detail(items[position]);
  
      }
  
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
          selection.setText("");
      }
  
  
      //another activity
      public void Detail(String id)
      //public void Detail()
      {   
          //Intent detail=new Intent(con, Detail.class);
  
          Intent grid=new Intent(this, Grid.class);
          grid.putExtra("IDP", id);
          this.startActivity(grid);
  
  
          //Toast.makeText(this, "list : " , Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>This is the xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Mulai dari :" /&gt;
  
      &lt;TextView
          android:id="@+id/DateStar"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="" /&gt;
  
      &lt;Button
          android:id="@+id/btn_PickDateStart"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Tanggal Awal" /&gt;
  
      &lt;TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Sampai dengan :" /&gt;
  
       &lt;TextView
          android:id="@+id/DateEnd"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="" /&gt;
  
      &lt;Button
          android:id="@+id/btn_PickDateEnd"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Tanggal Akhir" /&gt;
  
  
      &lt;TextView
          android:id="@+id/selection"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"/&gt;
  
  
      &lt;Spinner
          android:id="@+id/spinner"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:drawSelectorOnTop="false" /&gt;
  
   &lt;/LinearLayout&gt;
  </code></pre>