I am using a google example to insert a datepicker inside my application using dialogfragment
http://developer.android.com/guide/topics/ui/controls/pickers.html
But I'm not sure how to get the date after setting it (not a java expert). Dialog and datepicker are working fine and I can register this date, but can I do to make a callback in parent activity?
This is my piece of dialogue.
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
... and I invoke a dialogue from my activity with ...
public void showDatePickerDialog(View v) { DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); }
What is the correct way to call a method in my parent activity instead of Log.w? I believe this is due to passing the callback as a parameter or something else, but most of the links that I found on the Internet relate to previous versions without dialog fragments
EDIT: not sure if important but parent activity is declared as:
public class EditSessionActivity extends FragmentActivity {
SOLUTION: thanks to user Lecho this is the way to do it
DatePickerFragmennt.class
public class DatePickerFragment extends DialogFragment{ @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
... and parent activity EditSessionActivity.class ...
public class EditSessionActivity extends FragmentActivity implements OnDateSetListener { ... @Override public void onDateSet(DatePicker view, int year, int month, int day) {
android datepicker
Gonzalo Cao Jul 17 2018-12-17T00: 00Z
source share