Android Open Source - Books Date Picker Fragment

From Project

Back to project page Books.


The source code is released under:

Apache License

If you think the Android project Books listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.contender.books;
//  ww  w  .  j  a v  a 2  s.  c om
import java.util.Calendar;

import android.os.Bundle;

 * Implements the DatePickerFragment dialog used by {@link BookActivity}
 * <p>
 * Provides a UI for the user to set a date.
 * @author Paul Klinkenberg
public class DatePickerFragment extends DialogFragment

  DatePickerDialog.OnDateSetListener mListener;
  public void onAttach(Activity activity) {
    // Verify that the host activity implements the callback interface
    try {
      mListener = (DatePickerDialog.OnDateSetListener) activity;
    } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString() + " must implement OnDateSetListener");
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    Calendar c = BookActivity.dueDate;
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    // Create a new instance of DatePickerDialog and return it
    return new DatePickerDialog(getActivity(), mListener, year, month, day);

Java Source Code List