0

我知道如何用 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

4

1 回答 1

1

您可以创建interface,将其传递给DatePickerFragment(在构造函数中),然后在关闭对话框之前调用方法

例如:

你的界面:

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();
    }
}
于 2012-11-16T08:12:47.450 回答