本文整理匯總了Java中android.app.TimePickerDialog類的典型用法代碼示例。如果您正苦於以下問題:Java TimePickerDialog類的具體用法?Java TimePickerDialog怎麽用?Java TimePickerDialog使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TimePickerDialog類屬於android.app包,在下文中一共展示了TimePickerDialog類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onBtnChooseTimeDialogClicked
import android.app.TimePickerDialog; //導入依賴的package包/類
@OnClick(R.id.btn_choose_time_dialog)
public void onBtnChooseTimeDialogClicked() {
final Calendar calendar = Calendar.getInstance();
TimePickerDialog dialog = new TimePickerDialog(
this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String time = DateFormat.getTimeInstance(DateFormat.SHORT).format(calendar.getTime());
ToastUtils.showShortToast(time);
}
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
false
);
dialog.show();
}
示例2: showTime
import android.app.TimePickerDialog; //導入依賴的package包/類
private void showTime() {
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
int mHour = c.get(Calendar.HOUR_OF_DAY);
int mMinute = c.get(Calendar.MINUTE);
TimePickerDialog dialog =
new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
}
}, mHour, mMinute, true);
dialog.show();
}
示例3: getOnTimeSetListener
import android.app.TimePickerDialog; //導入依賴的package包/類
private static TimePickerDialog.OnTimeSetListener getOnTimeSetListener(final EditText txtDate) {
TimePickerDialog.OnTimeSetListener listener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String hour = hourOfDay + "";
if (hourOfDay < 10) {
hour = "0" + hourOfDay;
}
String min = minute + "";
if (minute < 10)
min = "0" + minute;
txtDate.setText(hour + ":" + min);
}
};
return listener;
}
示例4: taskDueTimeOnClickBehavior
import android.app.TimePickerDialog; //導入依賴的package包/類
@OnClick(R.id.task_due_time_content)
void taskDueTimeOnClickBehavior() {
TimePickerDialog.OnTimeSetListener time = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minuteOfHour) {
dueCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
dueCalendar.set(Calendar.MINUTE, minuteOfHour);
DateFormat sdf = android.text.format.DateFormat.getTimeFormat(getBaseContext());
dueTimeContent.setText(sdf.format(dueCalendar.getTime()));
setTime = true;
}
};
new TimePickerDialog(this, time,
dueCalendar.get(Calendar.HOUR_OF_DAY),
dueCalendar.get(Calendar.MINUTE), true).show();
}
示例5: pickTime
import android.app.TimePickerDialog; //導入依賴的package包/類
/**
* 彈出時間選擇對話框
* <p>
* 參數:
* title:標題
* datetime 指定時間 yyyy-MM-dd HH:mm或者HH:mm
* 返回:
* time:格式:HH:mm
*/
public static void pickTime(IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
String title = param.optString("title");
String date = param.optString("datetime");
final Calendar calendar = Calendar.getInstance();
if (!TextUtils.isEmpty(date)) {
if (date.contains(" ")) {
calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
} else {
calendar.setTime(DateUtil.convertString2Date(date, "HH:mm"));
}
}
DialogUtil.pickTime(webLoader.getPageControl().getActivity(), title, calendar, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String chooseTime = DateUtil.convertDate(calendar.getTime(), "HH:mm");
Map<String, Object> map = new HashMap<>();
map.put("time", chooseTime);
callback.applySuccess(map);
}
});
}
示例6: pickDateTime
import android.app.TimePickerDialog; //導入依賴的package包/類
/**
* 彈出日期時間選擇對話框
* <p>
* 參數:
* title:標題
* datetime 指定時間 yyyy-MM-dd HH:mm
* 返回:
* datetime:格式:yyyy-MM-dd HH:mm
*/
public static void pickDateTime(final IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
String title1 = param.optString("title1");
String title2 = param.optString("title2");
String date = param.optString("datetime");
final Calendar calendar = Calendar.getInstance();
if (!TextUtils.isEmpty(date)) {
calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd HH:mm"));
}
DialogUtil.pickDateTime(webLoader.getPageControl().getActivity(), title1, title2, calendar, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM-dd HH:mm");
Map<String, Object> map = new HashMap<>();
map.put("datetime", chooseDate);
callback.applySuccess(map);
}
});
}
示例7: onDateSet
import android.app.TimePickerDialog; //導入依賴的package包/類
public void onDateSet() {
final TimePickerDialog timePicker = new TimePickerDialog(getActivity(), this, hour, minute, true);
timePicker.setCanceledOnTouchOutside(true);
timePicker.setCancelable(true);
timePicker.setButton(DialogInterface.BUTTON_NEGATIVE, "Ahora", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("CET"));
timePicker.updateTime(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
onTimeSet(null, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
}
});
timePicker.show();
}
示例8: reminderTimePickerDialog
import android.app.TimePickerDialog; //導入依賴的package包/類
public void reminderTimePickerDialog() {
final Calendar calendar = Calendar.getInstance();
int mHour = calendar.get(Calendar.HOUR_OF_DAY);
int mMinute = calendar.get(Calendar.MINUTE);
final SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("hh:mm a", Locale.US);
final ToodooTimePickerDialog timePickerDialog = new ToodooTimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
reminderCalendar.set(Calendar.HOUR_OF_DAY, hour);
reminderCalendar.set(Calendar.MINUTE, minute);
selectedReminderValue = reminderCalendar.getTime();
reminderTimeValue = simpleTimeFormat.format(selectedReminderValue);
selectedReminder = reminderDateValue + " @ " + reminderTimeValue;
ToodooOptionsModel ToodooOptionsModel = toodooOptionsList.get(2);
ToodooOptionsModel.setOptionValue(selectedReminder);
mAdapter.notifyDataSetChanged();
}
}, mHour, mMinute, true);
timePickerDialog.show();
}
示例9: onCreateDialog
import android.app.TimePickerDialog; //導入依賴的package包/類
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
示例10: showTimePickerDialog
import android.app.TimePickerDialog; //導入依賴的package包/類
/**
* Shows time picker dialog and handles the time selected by user
* @param viewWhoIsCallingIt View whose time time needs to be updated after user selects time
* @param prefKey Preference for the key needed to be updated after user selects time
*/
private void showTimePickerDialog(final KeyValueView viewWhoIsCallingIt, final String prefKey) {
int time[] = TimeUtils.getCurrentTimeAsHourAndMinutes();
TimePickerDialog timePickerDialog = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
String selectedHour = i < 10 ? "0" + i: "" + i;
String selectedMinute = i1 < 10 ? "0" +i1: "" + i1;
String timeString = selectedHour + ":" + selectedMinute;
PreferenceHelper.putString(context, prefKey, timeString);
// We also backup the time here
// To get the prefKey for backup, its "last_" + prefKey
PreferenceHelper.putString(context, "last_" + prefKey, timeString);
viewWhoIsCallingIt.setValue(timeString);
addNextDayIfNecessary();
doCurrentAutoFunctions(true);
}
}, time[0], time[1], false);
timePickerDialog.show();
}
示例11: openTimePicker
import android.app.TimePickerDialog; //導入依賴的package包/類
private void openTimePicker(){
final Calendar c = Calendar.getInstance();
int mHour = c.get(Calendar.HOUR_OF_DAY);
int mMinute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
String date = btnPollExpiryTime.getText().toString();
btnPollExpiryTime.setText(date+" "+ hourOfDay + ":" + minute);
}
}, mHour, mMinute, false);
timePickerDialog.show();
}
示例12: displayTimePicker
import android.app.TimePickerDialog; //導入依賴的package包/類
private void displayTimePicker(final EditText destination) {
TimePickerFragment timePickerFragment = new TimePickerFragment();
timePickerFragment.setOnTimeSetListener(new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String displayTime = simpleTimeFormat.format(calendar.getTime());
destination.setText(displayTime);
switch (destination.getId()) {
case R.id.ane_start_time:
newEventPresenter.setStartTime(hourOfDay, minute);
break;
case R.id.ane_end_time:
newEventPresenter.setEndTime(hourOfDay, minute);
break;
}
}
});
timePickerFragment.show(getSupportFragmentManager(), TimePickerFragment.TAG);
}
示例13: showTimePicker
import android.app.TimePickerDialog; //導入依賴的package包/類
private void showTimePicker(final boolean startTime) {
final Calendar dateTime = startTime ? mEvent.localStart : mEvent.localEnd;
new TimePickerDialog(getContext(),
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
dateTime.set(Calendar.MINUTE, minute);
mSwitchAllDay.setChecked(false);
setTime(startTime);
}
},
dateTime.get(Calendar.HOUR_OF_DAY),
dateTime.get(Calendar.MINUTE),
false)
.show();
}
示例14: pickTime
import android.app.TimePickerDialog; //導入依賴的package包/類
/**
* Pick the time that the homework item is due in for.
*/
public void pickTime() {
TimePickerDialog dialog = new TimePickerDialog(AddExam.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
hours = hourOfDay;
minutes = minute;
exam.setPeriod(-1);
exam.setTime(Methods.convert(hourOfDay) + ":" + Methods.convert(minute));
timeChecker = true;
showUpdate();
showSubmit();
updateSwitcher(dateChecker, timeChecker);
}
}, hours, minutes, true);
dialog.show();
}
示例15: pickTime
import android.app.TimePickerDialog; //導入依賴的package包/類
/**
* Pick the time that the homework item is due in for.
*/
public void pickTime() {
TimePickerDialog dialog = new TimePickerDialog(AddHomework.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
hours = hourOfDay;
minutes = minute;
homeworkItem.setPeriod(-1);
homeworkItem.setTime(Methods.convert(hourOfDay) + ":" + Methods.convert(minute));
timeChecker = true;
showUpdate();
showSubmit();
updateSwitcher(dateChecker, timeChecker);
}
}, hours, minutes, true);
dialog.show();
}