I am simply trying to get the date from a datepicker dialog I created from one of the many android datepicker tutorials I found online. I seem to be going wrong somewhere in
You need to use an interface to get the data from the datepicker
to the caller fragment
:
public interface DateListener {
void passDate(String date);
}
Create a member variable called mListener
:
private DateListener mListener;
Override the onAttach
& onDetach
fragment
methods:
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (DateListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement DateListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
Next, implement this interface
in the caller fragment
and override the passDate
method:
@Override
public void passDate(String date) {
// Do something with 'date', yourEditText.setText(date) for the example
}
And you should be good to go.