我正在寻找在论坛和网络,但我找不到解决我的问题。 我正在使用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