Java tutorial
/** Copyright 2016 Alex Forbes This file is part of AirClock. AirClock is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. AirClock is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with AirClock. If not, see <http://www.gnu.org/licenses/>. */ package nz.al4.airclock; import android.app.Activity; import android.app.Dialog; import android.app.TimePickerDialog; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.text.format.DateFormat; import android.widget.TimePicker; /** * Time Picker to set the take off and landing times */ public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener { public TimePickerFragment() { // Required empty public constructor } OnAlarmTimePickedListener mCallback; public interface OnAlarmTimePickedListener { void onAlarmTimePicked(int hour, int minute); } @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (OnAlarmTimePickedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnAlarmTimePickedListener."); } } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { mCallback = (OnAlarmTimePickedListener) getActivity(); // Create a new instance of TimePickerDialog and return it return new TimePickerDialog(getActivity(), this, 0, 0, DateFormat.is24HourFormat(getActivity())); } @Override public void onTimeSet(TimePicker view, int hour, int minute) { // Bundle bundle = this.getArguments(); // String event = bundle.getString("event"); if (mCallback != null) { mCallback.onAlarmTimePicked(hour, minute); } } }