2 回答
TA贡献1777条经验 获得超10个赞
ExpenseFragment实现DatePickerDialog.OnDateSetListener,因此您需要使用getTargetFragment()而不是getActivity().
return new DatePickerDialog(getActivity(), (DatePickerDialog.OnDateSetListener) getTargetFragment(), year, month, day);
然后setTargetFragment在创建时使用DatePickerFragment.
mDisplayDate.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
DialogFragment datePicker = new DatePickerFragment();
datePicker.setTargetFragment(ExpenseFragment.this, 0);
datePicker.show(getFragmentManager(), "date picker");
}
});
TA贡献1868条经验 获得超4个赞
侦听器是在您的父 Fragment 中实现的,而不是您的父 Activity,因此您必须替换getActivity()
为getParentFragment()
return new DatePickerDialog(getActivity(), (DatePickerDialog.OnDateSetListener) getParentFragment(), year, month, day);
添加回答
举报