我正在尋找在論壇和網絡,但我找不到解決我的問題。 我正在使用DatePicker和Timepicker的程序中工作。在我的程序中,我使用Google的默認定義(http://developer.android.com/guide/topics/ui/controls/pickers.html),爲每個選擇器(時間和日期)分隔類。DatePicker和TimePicker API <11
public void showDatePickerDialog(View v) {
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
這是DatePickerFragment類:
public class DatePickerFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(),
(OnDateSetListener) getActivity(), year, month, day);
}
}
我看了一些關於支持庫和我的活動改爲FragmentActivity,但我得到了一些錯誤。 我應該如何更改我的代碼以在低於3.0的版本中實現? 提前謝謝!
讓你從android.support.v4進口 – pedromss
我做了這件事,我改變了擴展活動的FragmentActivity和getFragmentManager()getSupportFragmentManager(),但有錯誤,在最後的變化:S – RaZieL
最後,它的工作!感謝您的意見,請致電 – RaZieL