Android Open Source - logmypain Date Time Dialog Fragment

From Project

Back to project page logmypain.


The source code is released under:

GNU General Public License

If you think the Android project logmypain 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.logmypain.main.record.dialogs;
/* w  ww  . jav a  2 s  .  co  m*/
import java.util.Calendar;

import com.logmypain.R;

import android.os.Bundle;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TimePicker;

public class DateTimeDialogFragment extends DialogFragment {
   public interface DateTimeDialogListener {
          public void onReturnVal(DatePicker date, TimePicker time);
  public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      // Get the layout inflater
      final View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_date_time, null);
      final DatePicker date = (DatePicker)view.findViewById(;
      final TimePicker time = (TimePicker)view.findViewById(;
      Calendar cal = Calendar.getInstance();
      //long minDate = getArguments().getLong("minDate");
      //if (minDate != 0L){
      //  date.setMinDate(minDate);
      // Inflate and set the layout for the dialog
      // Pass null as the parent view because its going in the dialog layout
      // Add action buttons
      builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                   DateTimeDialogListener activity = (DateTimeDialogListener) getActivity();
                    activity.onReturnVal(date, time);
             .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
      return builder.create();


Java Source Code List