Example usage for android.app DatePickerDialog setOnCancelListener

List of usage examples for android.app DatePickerDialog setOnCancelListener

Introduction

In this page you can find the example usage for android.app DatePickerDialog setOnCancelListener.

Prototype

public void setOnCancelListener(@Nullable OnCancelListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is canceled.

Usage

From source file:org.hancel.adapters.customUi.DatePickerFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    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
    DatePickerDialog dt = new DatePickerDialog(getActivity(), (TrackDialog) getActivity(), year, month, day);
    dt.setButton(DialogInterface.BUTTON_POSITIVE, "OK", (TrackDialog) getActivity());
    dt.setOnCancelListener((TrackDialog) getActivity());
    return dt;//from   w w  w  . ja  v  a  2s .  c o m
}

From source file:com.shalzz.attendance.fragment.TimeTablePagerFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_logout) {
        userAccount.Logout();/*from  w ww .j  a  v a  2s  .c o m*/
        return true;
    } else if (item.getItemId() == R.id.menu_refresh) {
        // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator
        if (!mSwipeRefreshLayout.isRefreshing()) {
            mSwipeRefreshLayout.setRefreshing(true);
            mController.updatePeriods();
            return true;
        }
    } else if (item.getItemId() == R.id.menu_date) {
        Calendar today = Calendar.getInstance();
        today.setTime(new Date());
        DatePickerDialog mDatePickerDialog = new DatePickerDialog(mContext, onDateSetListener(),
                today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH));
        mDatePickerDialog.setOnCancelListener(dialog -> {
            mTracker.send(new HitBuilders.EventBuilder().setCategory("Scroll to Date").setAction("Button")
                    .setLabel("Cancel").build());
        });
        mDatePickerDialog.show();

        mTracker.send(new HitBuilders.EventBuilder().setCategory("Action").setAction("Scroll to Date").build());
        return true;
    } else if (item.getItemId() == R.id.menu_today) {
        mController.setToday();

        mTracker.send(
                new HitBuilders.EventBuilder().setCategory("Action").setAction("Scroll to Today").build());
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.whatsoft.contactbook.activity.ProfileActivity.java

@OnClick(R.id.edt_birthday)
void onClickBirthday() {
    birthday = edtDOB.getText().toString();
    Calendar calendar = Calendar.getInstance();
    DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
        @Override//from w  w w .j a  va  2  s  . c o m
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            edtDOB.setError(null);
            edtDOB.setText(String.format(Locale.ENGLISH, "%d/%d/%d", dayOfMonth, monthOfYear, year));
        }
    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            edtDOB.setText(birthday);
        }
    });
    datePickerDialog.show();
}