行。我花了好几个小时,我无法弄明白。我创建了一个单独的Class,它具有datepickerdialog片段,如下所示:
public abstract class DatePickerFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
}
}
调用此片段的代码是:
textViewToChange.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
DialogFragment newFragment = new DatePickerFragment() {
public void onDateSet(DatePicker view, int year, int month, int day) {
//TODO some stuff here
changed = true;
}
};
newFragment.show(getSupportFragmentManager(), "datePicker");
return changed;
}
});
我已经尝试了所有我能阅读的内容,但我无法弄清楚如何设置标题。显示的标题是今天的日期。我想设置标题并添加图标。任何帮助都会很棒!