我从Android Developers获取了原始的 TimePicker-Source
并将其粘贴到 Android Studio 中的一个新类中。Android Studio 抛出错误“此处不允许修改器‘静态’”。怎么了?这是来源:
public static class TimePickerFragment 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
}
}
顺便说一句:有没有一种简单的方法可以在活动中使用时间选择器?这里几乎所有的示例都使用“showDialog()”,它已被贬低。