我正在努力实现按下按钮时显示的TimePickerDialog。我已经按照Android Dev Topic上的Android文档进行操作,并且已将TimePicker类放在我要创建对话框的类中。但是,出于某种原因,当我将修饰符设置为静态时,我得到一个不允许使用的修饰符"错误。当我没有将该类作为静态时,我得到一个"类必须被声明为抽象或实现onTimeSet(我是)。以下是我的代码:
public class TimePicker extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
}
}
我还尝试在onTimeSet之前添加@Override,但是我收到一条关于它的消息,而不是从超类中覆盖该方法。