我從Android DevelopersTimepicker不是靜態的允許
了原來的TimePicker - 源代碼,並將其粘貼在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
}
}
而且順便說一句:有一種簡單的方法來在活動中使用timepicker?這裏幾乎所有的例子都是用「showDialog()」來處理的,它被depricated。
Java基礎...谷歌爲:我們何時應該使用靜態Java類 – Selvin