List of usage examples for android.widget DatePicker getMonth
public int getMonth()
From source file:Main.java
/** * @param datePicker/*from w w w .j av a 2 s . com*/ * @return date with the hours/minutes/seconds/milliseconds stripped off */ public static long getDate(DatePicker datePicker) { return getDate(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); }
From source file:Main.java
public static java.util.Date getDateFromDatePicker(DatePicker datePicker) { int day = datePicker.getDayOfMonth(); int month = datePicker.getMonth(); int year = datePicker.getYear(); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day);/*from w w w .jav a 2 s .c o m*/ return calendar.getTime(); }
From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java
public static String getTextOfView(View view) { Object textObj = null;//from w ww . j a v a 2s . co m if (view instanceof TextView) { textObj = ((TextView) view).getText(); if (view instanceof Switch) { boolean isOn = ((Switch) view).isChecked(); textObj = isOn ? "1" : "0"; } } else if (view instanceof Spinner) { Object selectedItem = ((Spinner) view).getSelectedItem(); if (selectedItem != null) { textObj = selectedItem.toString(); } } else if (view instanceof DatePicker) { DatePicker picker = (DatePicker) view; int y = picker.getYear(); int m = picker.getMonth(); int d = picker.getDayOfMonth(); textObj = String.format("%04d-%02d-%02d", y, m, d); } else if (view instanceof TimePicker) { TimePicker picker = (TimePicker) view; int h = picker.getCurrentHour(); int m = picker.getCurrentMinute(); textObj = String.format("%02d:%02d", h, m); } else if (view instanceof RadioGroup) { RadioGroup radioGroup = (RadioGroup) view; int checkedId = radioGroup.getCheckedRadioButtonId(); int childCount = radioGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View child = radioGroup.getChildAt(i); if (child.getId() == checkedId && child instanceof RadioButton) { textObj = ((RadioButton) child).getText(); break; } } } else if (view instanceof RatingBar) { RatingBar bar = (RatingBar) view; float rating = bar.getRating(); textObj = String.valueOf(rating); } return textObj == null ? "" : textObj.toString(); }
From source file:org.akop.crosswords.fragment.DatePickerFragment.java
private void notifyListener(DatePicker picker) { int year = picker.getYear(); int month = picker.getMonth() + 1; int day = picker.getDayOfMonth(); Activity activity = getActivity();/*from w w w .j a va2 s. c o m*/ if (activity instanceof OnDateSelectedListener) { OnDateSelectedListener listener = (OnDateSelectedListener) activity; listener.onDateSelected(new DateTime(year, month, day, 0, 0, 0)); } }
From source file:com.itcorea.coreonwallet.DatePickerDialogFragment.java
@TargetApi(11) @Override/*from ww w.ja va 2 s. c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle b = getArguments(); int y = b.getInt(YEAR); int m = b.getInt(MONTH); int d = b.getInt(DATE); final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d); if (hasJellyBeanAndAbove()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }
From source file:at.jclehner.rxdroid.DatePickerFragment.java
@Override public void onShow(DialogInterface dialogInterface) { if (Version.SDK_IS_JELLYBEAN_OR_NEWER) { final DatePickerDialog dialog = (DatePickerDialog) dialogInterface; dialog.getButton(Dialog.BUTTON_POSITIVE).setOnClickListener(new OnClickListener() { @TargetApi(11)/* w ww.j ava 2s . com*/ @Override public void onClick(View v) { final DatePicker picker = dialog.getDatePicker(); mListener.onDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth()); dialog.dismiss(); } }); } }
From source file:ca.ualberta.cs.shoven_habittracker.DatePickerFragment.java
@Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { TextView textView = (TextView) getActivity().findViewById(R.id.pickDateTextView); String monthStr = "0" + (datePicker.getMonth() + 1); String dayStr = "0" + datePicker.getDayOfMonth(); textView.setText(datePicker.getYear() + "-" + monthStr.substring(monthStr.length() - 2) + "-" + dayStr.substring(dayStr.length() - 2)); }
From source file:com.example.reminder.alarm.DatePickerFragment.java
@TargetApi(11) @Override/*from w w w . j a v a 2 s . c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle b = getArguments(); int y = b.getInt(YEAR); int m = b.getInt(MONTH); int d = b.getInt(DATE); // Jelly Bean introduced a bug in DatePickerDialog (and possibly // TimePickerDialog as well), and one of the possible solutions is // to postpone the creation of both the listener and the BUTTON_* . // // Passing a null here won't harm because DatePickerDialog checks for a null // whenever it reads the listener that was passed here. >>> This seems to be // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now. // // See my own question and answer, and details I included for the issue: // // http://stackoverflow.com/a/11493752/489607 // http://code.google.com/p/android/issues/detail?id=34833 // // Of course, suggestions welcome. final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d); if (hasJellyBeanAndAbove()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }
From source file:net.davidcesarino.android.common.ui.DatePickerDialogFragment.java
@TargetApi(11) @Override//from ww w . j a v a 2 s . c o m public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle b = getArguments(); int y = b.getInt(YEAR); int m = b.getInt(MONTH); int d = b.getInt(DATE); // Jelly Bean introduced a bug in DatePickerDialog (and possibly // TimePickerDialog as well), and one of the possible solutions is // to postpone the creation of both the listener and the BUTTON_* . // // Passing a null here won't harm because DatePickerDialog checks for a null // whenever it reads the listener that was passed here. >>> This seems to be // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now. // // See my own question and answer, and details I included for the issue: // // http://stackoverflow.com/a/11493752/489607 // http://code.google.com/p/android/issues/detail?id=34833 // // Of course, suggestions welcome. final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), y, m, d); if (isAffectedVersion()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }
From source file:com.cavega.DatePickerDialogSample.DatePickerDialogFragment.java
@TargetApi(11) @Override//ww w .java2 s.com public Dialog onCreateDialog(Bundle savedInstanceState) { // Jelly Bean introduced a bug in DatePickerDialog (and possibly // TimePickerDialog as well), and one of the possible solutions is // to postpone the creation of both the listener and the BUTTON_* . // // Passing a null here won't harm because DatePickerDialog checks for a null // whenever it reads the listener that was passed here. >>> This seems to be // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now. // // See my own question and answer, and details I included for the issue: // // http://stackoverflow.com/a/11493752/489607 // http://code.google.com/p/android/issues/detail?id=34833 // // Of course, suggestions welcome. final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), year, month, day); if (hasJellyBeanAndAbove()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }