純粹從本教程開始(http://developer.android.com/guide/topics/ui/controls/pickers.html)我可以輕鬆地顯示選取器,但不知道如何從中獲取實際值。Android - 我如何從時間選擇器獲取值?
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
}
}
public void showTimePickerDialog(View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getSupportFragmentManager(), "timePicker");
}
所以,如果我想要做的事與值獲得額外的興趣功能 - 表示將更改提交到SharedPreferences - 我應該做的都在那裏呢? – tuzion
是的。那就對了。 – prijupaul