我知道如何用Intent做到这一点,但我该怎么做....
以下是我必须打开DatePickerFragment
的代码:
DialogFragment newFragment = new DatePickerFragment();
Bundle bundle = new Bundle();
bundle.putString("date", (String) itemDict.get(Helper.convertKeyString(name, false)));
newFragment.setArguments(bundle);
newFragment.show(getFragmentManager(), "datePicker");
一旦打开,如何将我选择的日期传递回Activity
?
答案 0 :(得分:1)
您可以创建interface
,将其传递给DatePickerFragment
(在构造函数中),然后在关闭对话框之前调用method in
例如:
您的界面:
public interface OnDatePicked{
void onDatePicked();
}
您的活动:
public YourActivity implements OnDatePicked{
//your Activity
}
你的DatePickerFragment:
public class DatePickerFragment { //change Object to required type
private OnDatePicked listener;
public DatePickerFragment(OnDatePickedlistener){
this.listener=listener;
}
//required methods
protected void method(Object o){
//your stuff
listener.onDatePicked();
}
}