Search in sources :

Example 1 with OnDateSetListener

use of android.app.DatePickerDialog.OnDateSetListener in project android-app-common-tasks by multidots.

the class Common method showDatePickerDialog.

/**
     * use to show datepicker
     *
     * @param mContext
     * @param format    of the date format
     * @param mTextView in which you have to set selected date
     */
public static void showDatePickerDialog(final Context mContext, final String format, final TextView mTextView) {
    new DatePickerDialog(mContext, new OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            SimpleDateFormat dateFormatter = new SimpleDateFormat(format);
            dateTime.set(year, monthOfYear, dayOfMonth);
            mTextView.setText(dateFormatter.format(dateTime.getTime()));
        }
    }, dateTime.get(Calendar.YEAR), dateTime.get(Calendar.MONTH), dateTime.get(Calendar.DAY_OF_MONTH)).show();
}
Also used : OnDateSetListener(android.app.DatePickerDialog.OnDateSetListener) DatePickerDialog(android.app.DatePickerDialog) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with OnDateSetListener

use of android.app.DatePickerDialog.OnDateSetListener in project KJFrameForAndroid by kymjs.

the class ViewInject method getDateDialog.

/**
 * 用于创建PopupWindow封装一些公用属性
 */
// private PopupWindow createWindow(View view, int w, int h, int argb) {
// PopupWindow popupView = new PopupWindow(view, w, h);
// popupView.setFocusable(true);
// popupView.setBackgroundDrawable(new ColorDrawable(argb));
// popupView.setOutsideTouchable(true);
// return popupView;
// }
/**
 * 返回一个日期对话框
 */
public void getDateDialog(String title, final TextView textView) {
    final String[] time = SystemTool.getDataTime("yyyy-MM-dd").split("-");
    final int year = StringUtils.toInt(time[0], 0);
    final int month = StringUtils.toInt(time[1], 1);
    final int day = StringUtils.toInt(time[2], 0);
    DatePickerDialog dialog = new DatePickerDialog(textView.getContext(), new OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            textView.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
        }
    }, year, month - 1, day);
    dialog.setTitle(title);
    dialog.show();
}
Also used : OnDateSetListener(android.app.DatePickerDialog.OnDateSetListener) DatePickerDialog(android.app.DatePickerDialog) DatePicker(android.widget.DatePicker)

Example 3 with OnDateSetListener

use of android.app.DatePickerDialog.OnDateSetListener in project YhLibraryForAndroid by android-coco.

the class YHViewInject method getDateDialog.

/**
 * 用于创建PopupWindow封装一些公用属性
 */
// private PopupWindow createWindow(View view, int w, int h, int argb) {
// PopupWindow popupView = new PopupWindow(view, w, h);
// popupView.setFocusable(true);
// popupView.setBackgroundDrawable(new ColorDrawable(argb));
// popupView.setOutsideTouchable(true);
// return popupView;
// }
/**
 * 返回一个日期对话框
 */
public void getDateDialog(String title, final TextView textView) {
    final String[] time = StringUtils.getDataTime("yyyy-MM-dd").split("-");
    final int year = StringUtils.toInt(time[0], 0);
    final int month = StringUtils.toInt(time[1], 1);
    final int day = StringUtils.toInt(time[2], 0);
    DatePickerDialog dialog = new DatePickerDialog(textView.getContext(), new OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            textView.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
        }
    }, year, month - 1, day);
    dialog.setTitle(title);
    dialog.show();
}
Also used : OnDateSetListener(android.app.DatePickerDialog.OnDateSetListener) DatePickerDialog(android.app.DatePickerDialog) DatePicker(android.widget.DatePicker)

Aggregations

DatePickerDialog (android.app.DatePickerDialog)3 OnDateSetListener (android.app.DatePickerDialog.OnDateSetListener)3 DatePicker (android.widget.DatePicker)3 SimpleDateFormat (java.text.SimpleDateFormat)1