我有一个按钮可以拉出 DatePicker 片段,但我不知道如何根据选择的日期更改视图。我将 onDateSet 方法放在我的 main.java 中,这是调用片段的活动,目的是更改此方法中的视图,但是当日期更改时它什么也不做,我不确定我做错了什么。
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@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(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
}
我的 MainScreen.java 是
public class MainScreen extends FragmentActivity implements DatePickerDialog.OnDateSetListener {
static final int DATE_DIALOG_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
}
public void showDatePickerDialog(View v) {
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Intent intent = new Intent(this, January_1.class);
startActivity(intent);
}
}