我正在進行android自動測試,並嘗試在android中測試alarmclock應用程序。我想在TimePickerDialog彈出後獲取TimePicker,然後我們可以使用它調用方法的setCurrentHour(...)和setCurrentMinute()來以編程方式設置鬧鐘時間,而不是多次發送鍵盤事件。 謝謝。如何在TimePickerDialog彈出後獲取TimePicker
2
A
回答
0
當onTimeChanged
第一次觸發時,保存方法中傳遞的視圖。該視圖將作爲TimePicker的參考。
0
這可能有助於
Calendar mCalendar = Calendar.getInstance();
mHour = mCalendar.get(Calendar.HOUR_OF_DAY);
mMinute = mCalendar.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(mActivity, mTimeSetListener, mHour, mMinute, false);
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
mCalendar.set(Calendar.MINUTE, mMinute);
SimpleDateFormat mSDF = new SimpleDateFormat("hh:mm a");
String time = mSDF.format(mCalendar.getTime());
}
}
0
public class CustomTimePickerDialog extends TimePickerDialog {
public CustomTimePickerDialog(Context context, OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView) {
super(context, listener, hourOfDay, minute, is24HourView);
try {
Class<?> superClass = getClass().getSuperclass();
Field TimePickerField = superClass.getDeclaredField("mTimePicker");
TimePickerField.setAccessible(true);
TimePicker timePicker = (TimePicker) TimePickerField.get(this);
timePicker.setOnTimeChangedListener(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
public int getHour() {
return currentHour;
}
public int getMinute() {
return currentMinute;
}
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
super.onTimeChanged(view, hourOfDay, minute);
currentHour = hourOfDay;
currentMinute = minute;
}
private int currentHour;
private int currentMinute;
}
相關問題
- 1. 如何在彈出對話框後獲取對話框的實例(如DatePickerDialog,ProgressDialog,TimePickerDialog)
- 2. 如何在Android TimePicker中設置最短時間(不在TimePickerDialog中)
- 3. 如何獲取TimePickerDialog AM PM值
- 4. 有沒有辦法在不使用TimePickerDialog的情況下獲取TimePicker的時間?
- 5. 如何在AlertDialog中獲取價值TimePicker?
- 6. 如何設置按鈕單擊時彈出的TimePickerDialog?
- 7. 如何在打開彈出窗口後從gridview獲取commandargument值?
- 8. 獲取一個timepicker
- 9. 如何獲取Bootstrap timepicker日期對象?
- 10. 如何獲取Material TimePicker/DatePicker的尺寸?
- 11. 如何從jquery中獲取時間Timepicker
- 12. 獲取彈出窗口換頁後
- 13. 如何獲取彈出.circle固定?
- 14. 如何獲取insertcomponentpresentation窗口彈出?
- 15. Angular ui timepicker彈出不顯示
- 16. 最簡單的角度JS timepicker彈出
- 17. AngularUI Timepicker - 選擇時間彈出
- 18. 如何在獲取Ctrl + C後退出?
- 19. TimePicker無法獲取時間
- 20. 獲取Material Design TimePicker - android?
- 21. 從DatePicker和TimePicker獲取值
- 22. 獲取Timepicker值C#WPF
- 23. 從TimePicker獲取輸入 - Android
- 24. 如何在彈出窗口顯示時防止彈出獲取焦點
- 25. 如何在sumbit之後不彈出Richfaces彈出窗口?
- 26. 如何在彈出菜單設置爲wrap_content之後獲取Popup的高度?
- 27. 如何在ajax「成功後」彈出:
- 28. 如何在後臺彈出片段
- 29. ElectronJS - 如何在後臺彈出
- 30. 在Android timepicker取消
對不起,我沒有清楚地說明問題。我們無法觸摸android中的鬧鐘應用程序的源代碼,但只是測試它... – user402068 2010-07-28 00:46:42