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


Java OnTimeChangedListener类代码示例

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


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

示例1: onTimeButtonClicked

import android.widget.TimePicker.OnTimeChangedListener; //导入依赖的package包/类
private void onTimeButtonClicked()
{
	mTimeLayout = (LinearLayout)mLayoutInflater.inflate(R.layout.time_dialog, null);
	mTimePicker = (TimePicker)mTimeLayout.findViewById(R.id.time_picker);
	mTimePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
		
		@Override
		public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
			// TODO Auto-generated method stub
			mToDoItemInfo.setTime_hour(hourOfDay);
			mToDoItemInfo.setTime_minute(minute);
			mTimeString = mToDoItemInfo.getTimeString();
		}
	});
	new AlertDialog.Builder(mContext)
	.setTitle(getResources().getString(R.string.time_dialog_title))
	.setView(mTimeLayout)
	.setPositiveButton(getResources().getString(R.string.time_dialog_save_button_default_text), new DialogInterface.OnClickListener() {
		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			if(mTimeString == null){
				mTimeString = String.format("%02d:%02d", Calendar.getInstance().get(Calendar.HOUR_OF_DAY), Calendar.getInstance().get(Calendar.MINUTE));
			}
			mTimeButton.setText(mTimeString);
		}
	})
	.setNegativeButton(getResources().getString(R.string.time_dialog_cancel_button_default_text), null)
	.show();
}
 
开发者ID:oldoldb,项目名称:DouDouToDoList,代码行数:32,代码来源:EditItemView.java

示例2: onCreate

import android.widget.TimePicker.OnTimeChangedListener; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_alarm_app);
	// init();

	// private void init(){

	mTimePicker = (TimePicker) findViewById(R.id.timePicker1);
	set = (Button) findViewById(R.id.set);
	cancel = (Button) findViewById(R.id.cancel);
	//mTitleTv = (TextView) findViewById(R.id.showTime);
	btn_back = (Button)findViewById(R.id.btn_back);

	c.setTimeInMillis(System.currentTimeMillis());

	// �x�a���s��ť
	set.setOnClickListener(this);
	cancel.setOnClickListener(this);
	btn_back.setOnClickListener(this);
	// �]�m24�p�ɨ�
	mTimePicker.setIs24HourView(false);
	mTimePicker.setOnTimeChangedListener(new OnTimeChangedListener() {

		@Override
		public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {

			AlarmApp.setHour = hourOfDay;
			AlarmApp.setMinute = minute;
			// int setHour=c.get(Calendar.HOUR_OF_DAY);
			// int setMinute=c.get(Calendar.MINUTE);
		}
	});

}
 
开发者ID:minerva1218,项目名称:TestGit,代码行数:36,代码来源:AlarmApp.java

示例3: createTime

import android.widget.TimePicker.OnTimeChangedListener; //导入依赖的package包/类
private void createTime(final int _type, Activity _activity, final long _maxDate, final long _minDate) {
	this.timePicker = new TimePicker(_activity);
	this.timePicker.setIs24HourView(true);
	this.timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
	this.timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));

	calendar.setTimeInMillis(_maxDate);
	final int _maxHour = calendar.get(Calendar.HOUR_OF_DAY);
	final int _maxMinute = calendar.get(Calendar.MINUTE);

	calendar.setTimeInMillis(_minDate);
	final int _minHour = calendar.get(Calendar.HOUR_OF_DAY);
	final int _minMinute = calendar.get(Calendar.MINUTE);

	calendar.setTimeInMillis(System.currentTimeMillis());
	final String _maxStr = String.format(Locale.getDefault(), "%d-%02d-%02d %02d:%02d:00", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH),
			_maxHour, _maxMinute);
	final String _minStr = String.format(Locale.getDefault(), "%d-%02d-%02d %02d:%02d:00", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH),
			_minHour, _minMinute);

	this.timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
		@Override
		public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
			if (_type == 0) {
				if (_maxDate > _minDate) {
					String _val = String.format(Locale.getDefault(), "%d-%02d-%02d %02d:%02d:00", datePicker.getYear(), datePicker.getMonth() + 1, datePicker.getDayOfMonth(), hourOfDay, minute);
					long _currentTime = getTime(_val);
					if (_currentTime > _maxDate) { // 当前值大于最大值
						calendar.setTimeInMillis(_maxDate);
						datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), null);
						timePicker.setCurrentHour(_maxHour);
						timePicker.setCurrentMinute(_maxMinute);
					} else if (_currentTime < _minDate) { // 当前值小于最小值
						calendar.setTimeInMillis(_minDate);
						datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), null);
						timePicker.setCurrentHour(_minHour);
						timePicker.setCurrentMinute(_minMinute);
					}
				}
			} else {
				if (getTime(_maxStr) > getTime(_minStr)) {
					if (hourOfDay < _minHour) {
						timePicker.setCurrentHour(_minHour);
					}

					if (hourOfDay > _maxHour) {
						timePicker.setCurrentHour(_maxHour);
					}

					if (hourOfDay == _minHour) { // 如果当前选中时间的小时 =
													// 最小值,那么就比较分钟
						if (minute < _minMinute) {
							timePicker.setCurrentMinute(_minMinute);
						}
					}

					if (hourOfDay == _maxHour) { // 如果当前选中时间的小时 =
													// 最大值,那么就比较分钟
						if (minute > _maxMinute) {
							timePicker.setCurrentMinute(_maxMinute);
						}
					}
				}
			}
		}
	});

}
 
开发者ID:do-android,项目名称:do_DateTimePicker,代码行数:69,代码来源:do_DateTimePicker_Model.java


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