-
Notifications
You must be signed in to change notification settings - Fork 562
Betterpickers Datepicker Validation
Prashant Patel edited this page Jun 7, 2018
·
1 revision
XYZActivity implements CalendarDatePickerDialogFragment.OnDateSetListener, TimePickerDialogFragment.TimePickerDialogHandler
etDOB.setFocusable(false); etDOB.setClickable(true); etDOB.setLongClickable(false); etDOB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { rlDOB.performClick(); } });
rlDOB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MonthAdapter.CalendarDay maxDate = new MonthAdapter.CalendarDay(Calendar.getInstance().get(Calendar.YEAR) - 18, Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
MonthAdapter.CalendarDay minDate = new MonthAdapter.CalendarDay((Calendar.getInstance().get(Calendar.YEAR) - 100), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
if (callDobPicker == null) { callDobPicker = new CalendarDatePickerDialogFragment() .setFirstDayOfWeek(Calendar.SUNDAY)
.setDoneText("Select") .setCancelText("Cancel") .setDateRange(minDate, maxDate) .setThemeCustom(R.style.MyCustomBetterPickersDialogs1) .setOnDateSetListener(ProspectPersonalFragment.this); }
if (callDobPicker.isVisible() == true) { callDobPicker.dismiss(); } callDobPicker.show(getChildFragmentManager(), FRAG_TAG_DATE_PICKER); // for fragment // callDobPicker.show(getSupportFragmentManager(), FRAG_TAG_DATE_PICKER); // for activity
} });
@Override public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) { App.showLog(TAG, "---" + year + "---" + monthOfYear + "---" + dayOfMonth); strDob = dayOfMonth + "/" + (monthOfYear + 1) + "/" + year; etDOB.setText(strDob); }
rlCallDateTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MonthAdapter.CalendarDay maxDate = new MonthAdapter.CalendarDay(Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
MonthAdapter.CalendarDay minDate = new MonthAdapter.CalendarDay((Calendar.getInstance().get(Calendar.YEAR) - 100), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
if (calDatePicker == null) { calDatePicker = new CalendarDatePickerDialogFragment() .setFirstDayOfWeek(Calendar.SUNDAY) .setDoneText("Select") .setCancelText("Cancel") .setDateRange(minDate, maxDate) .setThemeCustom(R.style.MyCustomBetterPickersDialogs1) .setOnDateSetListener(ActNewCallTest.this); }
if (calDatePicker.isVisible() == true) { calDatePicker.dismiss(); }
//111-- calDatePicker.setPreselectedDate(1991,6,21); calDatePicker.show(getSupportFragmentManager(), FRAG_TAG_DATE_PICKER);
calDatePicker.setOnDismissListener(new OnDialogDismissListener() { @Override public void onDialogDismiss(DialogInterface dialoginterface) {
TimePickerBuilder tpb = new TimePickerBuilder() .setFragmentManager(getSupportFragmentManager()) .setStyleResId(R.style.BetterPickersDialogFragment); tpb.show(); } });
} });
@Override public void onDialogTimeSet(int reference, int hourOfDay, int minute) { strTime = String.format("%02d", hourOfDay) + ":" + String.format("%02d", minute);
//etCallDateTime.setText(App.get_dd_MM_yyyy_hh_mm(strDate + " " + strTime)); etCallDateTime.setText(App.convertFormat("dd/MM/yyyy HH:mm", "dd/MM/yyyy hh:mm a", strDate + " " + strTime)); }
public static String convertFormat(String inFormat, String opFormat, String data_time) { DateFormat f1 = new SimpleDateFormat(inFormat); Date d = null; try { d = f1.parse(data_time); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } DateFormat f2 = new SimpleDateFormat(opFormat); String x = f2.format(d); return x; }