title: calendar date selection for launching new activity
body: <p>Main activity contain action bar with button which display a calendar on same screen. 
  I want to launch a new activity when date is selected in the calendar view.
   for that purpose i write the code like this.</p>
  
  <pre><code>public class Main extends Activity {
      CalendarView cal;
      String d,m,y;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          LinearLayout llAppointment, llAdmitPatient, llAdmitDischarge, lle_counsults, llSecondOpinion, llQandA;
          cal = (CalendarView) findViewById(R.id.calndrView);
          llAppointment = (LinearLayout) findViewById(R.id.LLAppointment);
          llAdmitPatient = (LinearLayout) findViewById(R.id.LLAdmitPatient);
          llAdmitDischarge = (LinearLayout) findViewById(R.id.LLAdmitDischarge);
          lle_counsults = (LinearLayout) findViewById(R.id.LLE_consults);
          llSecondOpinion=(LinearLayout) findViewById(R.id.LLSecondOpinions);
          llQandA = (LinearLayout) findViewById(R.id.LLQandA);
  
  
          //appointments 
          llAppointment.setOnClickListener(new OnClickListener() {
  
              @SuppressLint("SimpleDateFormat")
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Calendar c = Calendar.getInstance();
                  SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
                  String Date = df.format(c.getTime());
  
  
                   String day=Date.substring(0,2);
                   String month=Date.substring(3,5);
                   String year=Date.substring(8,10);
  
              d=day;m=month;y=year;
  
                  Intent intent = new Intent(Main.this, AllPatientsActivity.class);
                  intent.putExtra("day", day);
                  intent.putExtra("month", month);
                  intent.putExtra("year", year);
  
                  startActivity(intent);
  
  
              }
          });
  
          // Admitted patients
  
          llAdmitPatient.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent= new Intent(Main.this, AdmittedPatients.class);
                  startActivity(intent);
              }
          });
          // Admit-Discharge
          llAdmitDischarge.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Main.this, AdmitDischarge.class);
                  startActivity(intent);
              }
          });
          //E-consultant
          lle_counsults.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Main.this, EConsultant.class);
                  startActivity(intent);
              }
          });
          //Second Opinion
          llSecondOpinion.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Main.this, SecondOpinion.class);
                  startActivity(intent);
              }
          });
          //Question and answer
          llQandA.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(Main.this, QAndA.class);
                  startActivity(intent);
              }
          });
  
          cal.setOnDateChangeListener(new OnDateChangeListener() {
  
              @Override
              public void onSelectedDayChange(CalendarView view, int year,
                      int month, int day) {
                  // TODO Auto-generated method stub
                  Toast.makeText(getBaseContext(),
                          day + "/" + month + "/" + year, Toast.LENGTH_SHORT)
                          .show();
  
  
  
                  if(Integer.parseInt(d)==day &amp;&amp; Integer.parseInt(m)==month &amp;&amp; Integer.parseInt(y)==year){
                      Toast.makeText(Main.this, "day:"+day+"d"+d+"month:"+month+"m"+m+"year:"+year+"y"+y, Toast.LENGTH_LONG).show();
                  }
  
  
                  Intent intent = new Intent(Main.this, AllPatientsActivity.class);
                  intent.putExtra("day", day);
                  intent.putExtra("month", month);
                  intent.putExtra("year", year);
                  startActivity(intent);
              }
  
          });
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu items for use in the action bar
  
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.main_activity_actions, menu);
  
          return super.onCreateOptionsMenu(menu);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle presses on the action bar items
          switch (item.getItemId()) {
          case R.id.action_calendar:
              Toast.makeText(this, "Menu Item 1 selected", Toast.LENGTH_SHORT)
                      .show();
              cal.setVisibility(View.VISIBLE);
  
              return true;
          default:
              return super.onOptionsItemSelected(item);
          }
      }
  }
  </code></pre>
  
  <p>When I press action bar button it should launch calendarView and if i selected a date in that calendar view it should launch second activity showing this date. but problem is that this code does not allow mi to select date other than this month, because as soon as this month changes while scrolling it fires event.
  what change should I do in the code so that my new activity will launch with correct date</p>