当前位置: 首页>>代码示例>>Java>>正文


Java OnDateChangedListener类代码示例

本文整理汇总了Java中android.widget.DatePicker.OnDateChangedListener的典型用法代码示例。如果您正苦于以下问题:Java OnDateChangedListener类的具体用法?Java OnDateChangedListener怎么用?Java OnDateChangedListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OnDateChangedListener类属于android.widget.DatePicker包,在下文中一共展示了OnDateChangedListener类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: normalize

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
/**
 * Sets the current, min, and max values on the given DatePicker and ensures that
 * min <= current <= max, adjusting current and max if needed.
 *
 * @param year The current year to set.
 * @param month The current month to set. 0-based.
 * @param day The current day to set.
 * @param minMillisUtc The minimum allowed date, in milliseconds from the epoch according to a
 *                     proleptic Gregorian calendar (no Julian switch).
 * @param maxMillisUtc The maximum allowed date, in milliseconds from the epoch according to a
 *                     proleptic Gregorian calendar (no Julian switch).
 */
public static void normalize(DatePicker picker, final OnDateChangedListener listener,
        int year, int month, int day, long minMillisUtc, long maxMillisUtc) {
    DateAndMillis currentDate = DateAndMillis.create(year, month, day);
    DateAndMillis minDate = DateAndMillis.create(minMillisUtc);
    DateAndMillis maxDate = DateAndMillis.create(maxMillisUtc);

    // Ensure min <= current <= max, adjusting current and max if needed.
    if (maxDate.millisForPicker < minDate.millisForPicker) {
        maxDate = minDate;
    }
    if (currentDate.millisForPicker < minDate.millisForPicker) {
        currentDate = minDate;
    } else if (currentDate.millisForPicker > maxDate.millisForPicker) {
        currentDate = maxDate;
    }

    setLimits(picker, currentDate.millisForPicker, minDate.millisForPicker,
            maxDate.millisForPicker);
    picker.init(currentDate.year, currentDate.month, currentDate.day, listener);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:33,代码来源:DateDialogNormalizer.java

示例2: createResponseComponent

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
@Override
protected void createResponseComponent(ViewGroup responseComponent) {
    datePicker = new DatePicker(getActivity());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    datePicker.setLayoutParams(params);
    Calendar c = Calendar.getInstance();
    datePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH),
            new OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker view, int newYear, int newMonth, int newDay) {
                    getResponse().setResponse((newMonth + 1) + "-" + newDay + "-" + newYear);
                }
            });
    responseComponent.addView(datePicker);
    updateDate(getResponse().getText());
}
 
开发者ID:DukeMobileTech,项目名称:AndroidSurvey,代码行数:19,代码来源:DateFragment.java

示例3: beforeAddViewHook

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
protected DatePicker beforeAddViewHook(ViewGroup component) {
    DatePicker datePicker = new DatePicker(getActivity());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    datePicker.setLayoutParams(params);
    datePicker.setCalendarViewShown(false);
    Calendar c = Calendar.getInstance();
    datePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH),
            new OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker view, int newYear,
                                          int newMonth, int newDay) {
                    mDay = newDay;
                    mMonth = newMonth;
                    mYear = newYear;
                    setResponseText();
                }
            });
    component.addView(datePicker);
    return datePicker;
}
 
开发者ID:DukeMobileTech,项目名称:AndroidSurvey,代码行数:23,代码来源:DateQuestionFragment.java

示例4: normalize

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
/**
 * Normalizes an existing DateDialogPicker changing the default date if
 * needed to comply with the {@code min} and {@code max} attributes.
 */
static void normalize(DatePicker picker, OnDateChangedListener listener,
        int year, int month, int day, int hour, int minute, long min, long max) {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    calendar.clear();
    calendar.set(year, month, day, hour, minute, 0);
    if (calendar.getTimeInMillis() < min) {
        calendar.clear();
        calendar.setTimeInMillis(min);
    } else if (calendar.getTimeInMillis() > max) {
        calendar.clear();
        calendar.setTimeInMillis(max);
    }
    picker.init(
            calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), listener);

    setLimits(picker, min, max);
}
 
开发者ID:openresearch,项目名称:android-chromium-view,代码行数:23,代码来源:DateDialogNormalizer.java

示例5: normalize

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
/**
 * Normalizes an existing DateDialogPicker changing the default date if
 * needed to comply with the {@code min} and {@code max} attributes.
 */
static void normalize(DatePicker picker, OnDateChangedListener listener,
        int year, int month, int day, int hour, int minute, long minMillis, long maxMillis) {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    calendar.clear();
    calendar.set(year, month, day, hour, minute, 0);
    if (calendar.getTimeInMillis() < minMillis) {
        calendar.clear();
        calendar.setTimeInMillis(minMillis);
    } else if (calendar.getTimeInMillis() > maxMillis) {
        calendar.clear();
        calendar.setTimeInMillis(maxMillis);
    }
    picker.init(
            calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), listener);

    setLimits(picker, minMillis, maxMillis);
}
 
开发者ID:mogoweb,项目名称:chromium_webview,代码行数:23,代码来源:DateDialogNormalizer.java

示例6: initView

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
private void initView(View view) {
    final OnDateChangedListener dateChangedListener = this;
    dateButton = (Button) view.findViewById(R.id.buttonDate);
    dateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            DatePickerFragment datePickerFragment = new DatePickerFragment();
            datePickerFragment.setProfileAndOnDateChangedListener(profile, dateChangedListener);
            datePickerFragment.show(getActivity().getSupportFragmentManager(), "datePicker");
        }
    });
    updateButtonText();

    nameView = (EditText) view.findViewById(R.id.editTextName);
    if (profile.getName() != null) {
        nameView.setText(profile.getName());
    }
}
 
开发者ID:tschut,项目名称:matchmylife,代码行数:19,代码来源:ProfileEditFragment.java

示例7: onDateButtonClicked

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
private void onDateButtonClicked()
{
	mDateLayout = (LinearLayout)mLayoutInflater.inflate(R.layout.date_dialog, null);
	mDatePicker = (DatePicker)mDateLayout.findViewById(R.id.date_picker);
	final Calendar calendar = Calendar.getInstance();
	mDatePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new OnDateChangedListener() {
		
		@Override
		public void onDateChanged(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			// TODO Auto-generated method stub
			mToDoItemInfo.setDate_year(year);
			mToDoItemInfo.setDate_month(monthOfYear);
			mToDoItemInfo.setDate_day(dayOfMonth);
			mDateString = mToDoItemInfo.getDateString();
		}
	});
	new AlertDialog.Builder(mContext)
	.setTitle(getResources().getString(R.string.date_dialog_title))
	.setView(mDateLayout)
	.setPositiveButton(getResources().getString(R.string.date_dialog_save_button_default_text), new DialogInterface.OnClickListener() {
		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			if(mDateString == null){
				mDateString = String.format("%04d-%02d-%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
			}
			mDateButton.setText(mDateString);
		}
	})
	.setNegativeButton(getResources().getString(R.string.date_dialog_cancel_button_default_text), null)
	.show();
}
 
开发者ID:oldoldb,项目名称:DouDouToDoList,代码行数:35,代码来源:EditItemView.java

示例8: setDateToDatePicker

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
/**
 * Convenience function to set the picker date.
 * @param aCal - Date to set, if null, use getNow().
 * @param aDatePicker - Widget to set.
 * @param aListener - part of the Widget's params
 * @return Returns the Calendar object used.
 */
static public Calendar setDateToDatePicker(Calendar aCal, DatePicker aDatePicker, OnDateChangedListener aListener) {
	if (aCal==null)
		aCal = getNow();
	if (aDatePicker!=null)
		aDatePicker.init(aCal.get(Calendar.YEAR),aCal.get(Calendar.MONTH),aCal.get(Calendar.DAY_OF_MONTH),aListener);
	return aCal;
}
 
开发者ID:baracudda,项目名称:androidBits,代码行数:15,代码来源:DbDateTime.java

示例9: onCreateView

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
/**
 * Create and return the user interface view for this fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    int theme = getArguments().getInt("theme");
    int initialYear = getArguments().getInt("year");
    int initialMonth = getArguments().getInt("month");
    int initialDay = getArguments().getInt("day");
    Date minDate = (Date) getArguments().getSerializable("minDate");
    Date maxDate = (Date) getArguments().getSerializable("maxDate");

    // Unless we inflate using a cloned inflater with a Holo theme,
    // on Lollipop devices the DatePicker will be the new-style
    // DatePicker, which is not what we want. So we will
    // clone the inflater that we're given but with our specified
    // theme, then inflate the layout with this new inflater.

    Context contextThemeWrapper = new ContextThemeWrapper(
            getActivity(),
            theme == SlideDateTimePicker.HOLO_DARK ?
                     android.R.style.Theme_Holo :
                     android.R.style.Theme_Holo_Light);

    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

    View v = localInflater.inflate(R.layout.fragment_date, container, false);

    mDatePicker = (CustomDatePicker) v.findViewById(R.id.datePicker);
    // block keyboard popping up on touch
    mDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
    mDatePicker.init(
        initialYear,
        initialMonth,
        initialDay,
        new OnDateChangedListener() {

            @Override
            public void onDateChanged(DatePicker view, int year,
                    int monthOfYear, int dayOfMonth)
            {
                mCallback.onDateChanged(year, monthOfYear, dayOfMonth);
            }
        });

    if (minDate != null)
        mDatePicker.setMinDate(minDate.getTime());

    if (maxDate != null)
        mDatePicker.setMaxDate(maxDate.getTime());

    return v;
}
 
开发者ID:jjobes,项目名称:SlideDateTimePicker,代码行数:56,代码来源:DateFragment.java

示例10: setProfileAndOnDateChangedListener

import android.widget.DatePicker.OnDateChangedListener; //导入依赖的package包/类
public void setProfileAndOnDateChangedListener(Profile profile, OnDateChangedListener listener) {
    this.profile = profile;
    this.listener = listener;
}
 
开发者ID:tschut,项目名称:matchmylife,代码行数:5,代码来源:DatePickerFragment.java


注:本文中的android.widget.DatePicker.OnDateChangedListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。